From b9cdbe4e8dc02cff07af9e0fa28adb2372337963 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Wed, 23 Oct 2013 03:17:22 +0000 Subject: [PATCH] Commit the (hopefully) non-contentuous NEW_STRING changes. This is the batch that's largely mechanical and for formats, at least mostly passing testo. It's all still disabled by default and much of it is pretty dicey, but this patch has been growing in my tree and I wanted to get it committed. Later, when we take out the NEW_STRING stuff, I'll refactor the stuff around these changes which were often done to preserve fidelity to the original C versions even when there is a better way now. --- gpsbabel/alan.cc | 12 ++- gpsbabel/bcr.cc | 7 +- gpsbabel/bushnell.cc | 3 - gpsbabel/cet_util.cc | 6 +- gpsbabel/compegps.cc | 23 +++--- gpsbabel/cst.cc | 8 ++ gpsbabel/destinator.cc | 14 +++- gpsbabel/dmtlog.cc | 78 +++++++++++++++++-- gpsbabel/duplicate.cc | 2 +- gpsbabel/easygps.cc | 14 +++- gpsbabel/exif.cc | 5 +- gpsbabel/g7towin.cc | 4 + gpsbabel/garmin_device_xml.cc | 14 +++- gpsbabel/garmin_gpi.cc | 106 ++++++++++++++++++++----- gpsbabel/garmin_tables.cc | 23 +++--- gpsbabel/garmin_tables.h | 4 +- gpsbabel/garmin_txt.cc | 31 ++++++-- gpsbabel/glogbook.cc | 12 +++ gpsbabel/google.cc | 34 +++++++-- gpsbabel/googledir.cc | 55 +++++-------- gpsbabel/gpsutil.cc | 6 +- gpsbabel/gpx.cc | 31 +++++++- gpsbabel/gtrnctr.cc | 140 ++++++++++++++++++++++++++++------ gpsbabel/hiketech.cc | 26 ++++++- gpsbabel/holux.cc | 6 +- gpsbabel/html.cc | 12 ++- gpsbabel/humminbird.cc | 16 ++-- gpsbabel/ignrando.cc | 22 ++++-- gpsbabel/ik3d.cc | 7 +- gpsbabel/interpolate.cc | 10 +++ gpsbabel/kml.cc | 65 ++++++++++++++-- gpsbabel/lmx.cc | 36 +++++++-- gpsbabel/lowranceusr.cc | 62 ++++++++++++--- gpsbabel/maggeo.cc | 17 ++--- gpsbabel/magproto.cc | 61 +++++++++++---- gpsbabel/mapsend.cc | 30 ++++++-- gpsbabel/mapsource.cc | 90 ++++++++++++++++------ gpsbabel/mkshort.cc | 14 +++- gpsbabel/mmo.cc | 44 ++++++++--- gpsbabel/naviguide.cc | 23 ++++-- gpsbabel/navilink.cc | 14 ++-- gpsbabel/netstumbler.cc | 18 +++-- gpsbabel/nmea.cc | 12 ++- gpsbabel/osm.cc | 45 ++++++++++- gpsbabel/overlay.cc | 23 ++++-- gpsbabel/ozi.cc | 43 +++++++++-- gpsbabel/pcx.cc | 14 ++-- gpsbabel/pocketfms_fp.cc | 40 ++++++++++ gpsbabel/pocketfms_wp.cc | 10 +++ gpsbabel/psitrex.cc | 15 +++- gpsbabel/raymarine.cc | 28 +++---- gpsbabel/skyforce.cc | 7 +- gpsbabel/skytraq.cc | 5 +- gpsbabel/sort.cc | 8 ++ gpsbabel/stmsdf.cc | 47 ++++++------ gpsbabel/stmwpp.cc | 9 ++- gpsbabel/tef_xml.cc | 20 ++++- gpsbabel/text.cc | 13 +++- gpsbabel/tiger.cc | 7 +- gpsbabel/tmpro.cc | 21 ++++- gpsbabel/tomtom.cc | 12 +++ gpsbabel/tpg.cc | 25 +++--- gpsbabel/trackfilter.cc | 20 ++++- gpsbabel/transform.cc | 25 +++++- gpsbabel/unicsv.cc | 24 +++--- gpsbabel/vitosmt.cc | 4 + gpsbabel/waypt.cc | 42 +++++++++- gpsbabel/wfff_xml.cc | 16 ++++ gpsbabel/xcsv.cc | 4 + gpsbabel/yahoo.cc | 15 ++++ 70 files changed, 1365 insertions(+), 394 deletions(-) diff --git a/gpsbabel/alan.cc b/gpsbabel/alan.cc index fbceceeee..763742bf2 100644 --- a/gpsbabel/alan.cc +++ b/gpsbabel/alan.cc @@ -443,6 +443,12 @@ static void str2lab(char* dest, const char* src, int len, const char* fmt, } } +static void str2lab(char* dest, const QString& src, int len, const char* fmt, + int n) +{ + str2lab(dest, CSTR(src), len, fmt, n); +} + static void pack_time(time_t t, int32_t* date, int32_t* time) { struct tm* tm; @@ -818,7 +824,7 @@ static void trl_track_hdr(const route_head* TL) } if (TL->rte_name != NULL) { - strncpy(trkhdr[idx].name, TL->rte_name, TRK_NAME_LEN); + strncpy(trkhdr[idx].name, CSTRc(TL->rte_name), TRK_NAME_LEN); } if (*(trkhdr[idx].name) == '\0') { sprintf(trkhdr[idx].name, "T%03d", idx); @@ -826,8 +832,8 @@ static void trl_track_hdr(const route_head* TL) trkhdr[idx].name[TRK_NAME_LEN-1] = '\0'; if (TL->rte_desc != NULL) { - strncpy(trkhdr[idx].comment, TL->rte_desc, TRK_COMMENT_LEN); - l = strlen(TL->rte_desc); + strncpy(trkhdr[idx].comment, CSTRc(TL->rte_desc), TRK_COMMENT_LEN); + l = strlen(CSTRc(TL->rte_desc)); if (l < TRK_COMMENT_LEN-1) { memset(trkhdr[idx].comment + l, ' ', TRK_COMMENT_LEN - l); } diff --git a/gpsbabel/bcr.cc b/gpsbabel/bcr.cc index 295acbd56..52fb79f73 100644 --- a/gpsbabel/bcr.cc +++ b/gpsbabel/bcr.cc @@ -319,8 +319,12 @@ bcr_data_read(void) *c = '\0'; } if (*str) { +#if NEW_STRINGS + wpt->shortname = str; +#else xfree(wpt->shortname); wpt->shortname = xstrdup(str); +#endif } } } @@ -455,7 +459,7 @@ bcr_route_header(const route_head* route) i = 0; QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) { - char* s1, *s2; + const char* s1, *s2; i++; wpt = (waypoint*) elem; @@ -487,6 +491,7 @@ bcr_route_header(const route_head* route) } else { sout = QString("%1,%2,@,0").arg(s1).arg(s1); } + bcr_write_line(fout, "STATION", &i, sout); xfree(s1); xfree(s2); diff --git a/gpsbabel/bushnell.cc b/gpsbabel/bushnell.cc index af2b2fe37..479e1b48d 100644 --- a/gpsbabel/bushnell.cc +++ b/gpsbabel/bushnell.cc @@ -232,7 +232,6 @@ bushnell_write_one(const waypoint* wpt) gbfile* file_out; static int wpt_count; char* fname; - char* ident; xasprintf(&fname, "%s-%d.wpt", ofname, wpt_count++); file_out = gbfopen_le(fname, "wb", MYNAME); @@ -241,7 +240,6 @@ bushnell_write_one(const waypoint* wpt) gbfputc(bushnell_get_icon_from_name(wpt->icon_descr), file_out); gbfputc(0x01, file_out); // Proximity alarm. 1 == "off", 3 == armed. - ident = mkshort(mkshort_handle, wpt->shortname); strncpy(tbuf, CSTRc(wpt->shortname), sizeof(tbuf)); tbuf[sizeof(tbuf)-1] = 0; gbfwrite(tbuf, sizeof(tbuf), 1, file_out); @@ -250,7 +248,6 @@ bushnell_write_one(const waypoint* wpt) gbfwrite(padding, sizeof(padding), 1, file_out); xfree(fname); - xfree(ident); gbfclose(file_out); } diff --git a/gpsbabel/cet_util.cc b/gpsbabel/cet_util.cc index f6026af72..c2b8274c4 100644 --- a/gpsbabel/cet_util.cc +++ b/gpsbabel/cet_util.cc @@ -994,9 +994,9 @@ cet_convert_waypt(const waypoint* wpt) w->wpt_flags.cet_converted = 1; #if NEW_STRINGS - w->shortname = cet_convert_string(CSTRc(wpt->shortname)); - w->description = cet_convert_string(CSTRc(wpt->description)); - w->notes = cet_convert_string(CSTRc(wpt->notes)); +// w->shortname = cet_convert_string(wpt->shortname); +// w->description = cet_convert_string(wpt->description); +// w->notes = cet_convert_string(wpt->notes); #else w->shortname = cet_convert_string(CSTRc(wpt->shortname)); w->description = cet_convert_string(CSTRc(wpt->description)); diff --git a/gpsbabel/compegps.cc b/gpsbabel/compegps.cc index 04ffe2bc6..43a59c49e 100644 --- a/gpsbabel/compegps.cc +++ b/gpsbabel/compegps.cc @@ -217,8 +217,13 @@ parse_wpt(char* buff) break; default: if (col > 7) { +#if NEW_STRINGS + wpt->description += " "; + wpt->description += c; +#else wpt->description = xstrappend(wpt->description, " "); wpt->description = xstrappend(wpt->description, c); +#endif } } } @@ -480,7 +485,7 @@ compegps_data_read(void) static void write_waypt_cb(const waypoint* wpt) { - char* name; + QString name; if (curr_index != target_index) { return; @@ -488,7 +493,7 @@ write_waypt_cb(const waypoint* wpt) name = (snlen > 0) ? mkshort_from_wpt(sh, wpt) : csv_stringclean(wpt->shortname, " "); - gbfprintf(fout, "W %s A ", name); + gbfprintf(fout, "W %s A ", CSTR(name)); gbfprintf(fout, "%.10f%c%c ", fabs(wpt->latitude), 0xBA, (wpt->latitude >= 0) ? 'N' : 'S'); gbfprintf(fout, "%.10f%c%c ", @@ -506,27 +511,24 @@ write_waypt_cb(const waypoint* wpt) wpt->icon_descr.isNull() ? "Waypoint" : wpt->icon_descr.toUtf8().data(), WAYPT_GET(wpt, proximity, 0)); } - xfree(name); } static void write_route_hdr_cb(const route_head* rte) { - char* name; curr_route = (route_head*) rte; curr_index++; if (curr_index != target_index) { return; } - name = rte->rte_name; + QString name = rte->rte_name; if (name != NULL) { name = csv_stringclean(name, ","); } else { name = xstrdup(" "); } - gbfprintf(fout, "R 16711680,%s,1,-1\n", name); - xfree(name); + gbfprintf(fout, "R 16711680,%s,1,-1\n", CSTR(name)); } static void @@ -592,11 +594,8 @@ write_trkpt_cb(const waypoint* wpt) if (track_info_flag != 0) { track_info_flag = 0; if (curr_track->rte_name != NULL) { - char* name; - - name = csv_stringclean(curr_track->rte_name, "|"); - gbfprintf(fout, "t 4294967295|%s|-1|-1\n", name); - xfree(name); + QString name = csv_stringclean(curr_track->rte_name, "|"); + gbfprintf(fout, "t 4294967295|%s|-1|-1\n", CSTR(name)); } } } diff --git a/gpsbabel/cst.cc b/gpsbabel/cst.cc index b2b2d8f45..f7d3f95e6 100644 --- a/gpsbabel/cst.cc +++ b/gpsbabel/cst.cc @@ -236,7 +236,11 @@ cst_data_read(void) line++; cin = lrtrim(buff); if (*cin != '\0') { +#if NEW_STRINGS + wpt->notes = QString::fromLatin1(cin); +#else wpt->notes = xstrdup(cin); +#endif } } else if (strcmp(cin + 2, "end") == 0) { data = 1; @@ -282,7 +286,11 @@ cst_data_read(void) track = route_head_alloc(); track_add_head(track); } else if (strncmp(name, "NAME:", 5) == 0) { +#if NEW_STRINGS + wpt->shortname = QString::fromLatin1(((char*)&name) + 5); +#else wpt->shortname = xstrdup(((char*)&name) + 5); +#endif } pow = strrchr(cin, '^'); diff --git a/gpsbabel/destinator.cc b/gpsbabel/destinator.cc index 351fc420b..4d213ec02 100644 --- a/gpsbabel/destinator.cc +++ b/gpsbabel/destinator.cc @@ -98,12 +98,12 @@ read_wcstr(const int discard) } static void -write_wcstr(const char* str) +write_wcstr(const QString& str) { int len; short* unicode; - unicode = cet_str_utf8_to_uni(str, &len); + unicode = cet_str_utf8_to_uni(CSTR(str), &len); gbfwrite((void*)unicode, 2, len + 1, fout); xfree(unicode); } @@ -394,8 +394,13 @@ destinator_wpt_disp(const waypoint* wpt) garmin_fs_t* gmsd = GMSD_FIND(wpt); write_wcstr(DST_DYN_POI); +#if NEW_STRINGS + write_wcstr((!wpt->shortname.isEmpty()) ? CSTRc(wpt->shortname) : "WPT"); + write_wcstr((!wpt->notes.isEmpty()) ? wpt->notes : wpt->description); +#else write_wcstr((wpt->shortname) ? CSTRc(wpt->shortname) : "WPT"); write_wcstr((wpt->notes) ? wpt->notes : wpt->description); +#endif write_wcstr(NULL); /* house number */ write_wcstr(GMSD_GET(addr, NULL)); /* street */ @@ -466,8 +471,13 @@ static void destinator_rtept_disp(const waypoint* wpt) { write_wcstr(DST_ITINERARY); +#if NEW_STRINGS + write_wcstr((!wpt->shortname.isEmpty()) ? wpt->shortname : "RTEPT"); + write_wcstr((!wpt->notes.isEmpty()) ? wpt->notes : wpt->description); +#else write_wcstr((wpt->shortname) ? CSTRc(wpt->shortname) : "RTEPT"); write_wcstr((wpt->notes) ? wpt->notes : wpt->description); +#endif gbfputint32(0, fout); gbfputdbl(0, fout); diff --git a/gpsbabel/dmtlog.cc b/gpsbabel/dmtlog.cc index da91854f1..bcb7408e7 100644 --- a/gpsbabel/dmtlog.cc +++ b/gpsbabel/dmtlog.cc @@ -39,7 +39,7 @@ static gbfile* fin, *fout; static char* xmlbin; static waypoint* xmlwpt; static route_head* xmltrk; -static char* xmlgrid; +static QString xmlgrid; static int xmldatum; static double xmlEasting, xmlNorthing; static double xmlLatitude, xmlLongitude; @@ -123,7 +123,7 @@ convert_datum(waypoint* wpt, int datum) static void finalize_pt(waypoint* wpt) { - if (strcmp(xmlgrid, "BNG") == 0) { + if (xmlgrid == "BNG") { GPS_Math_NGENToAiry1830LatLon(xmlEasting, xmlNorthing, &wpt->latitude, &wpt->longitude); xmldatum = DATUM_OSGB36; @@ -150,8 +150,12 @@ finalize_pt(waypoint* wpt) static void tlog3a_xgcb_version(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + if (args != "1") { +#else if (strcmp(args, "1") != 0) { - fatal(MYNAME ": Unsupported file version '%s'!\n", args); +#endif + fatal(MYNAME ": Unsupported file version '%s'!\n", CSTRc(args)); } } @@ -167,11 +171,20 @@ tlog3a_xgcb_data(xg_string args, const QXmlStreamAttributes* unused) char* bin; char* cin, *cout; char cl, ch; - +#if NEW_STRINGS +// This function needs rethinking. + len = args.length(); +#else len = strlen(args); +#endif bin = (char*) xmalloc((len >> 1) + 1); +#if NEW_STRINGS + char* cincopy = xstrdup(args); + cin = cincopy; +#else cin = (char*)args; +#endif cout = bin; cl = 0x10; @@ -200,6 +213,9 @@ tlog3a_xgcb_data(xg_string args, const QXmlStreamAttributes* unused) } xmlbin = bin; xmlbinsize = (cout - bin); +#if NEW_STRINGS + xfree(cincopy); +#endif } #endif @@ -211,7 +227,11 @@ tlog3b_xgcb_tfna(xg_string args, const QXmlStreamAttributes* unused) xmltrk = route_head_alloc(); track_add_head(xmltrk); } +#if NEW_STRINGS + xmltrk->rte_name = args; +#else xmltrk->rte_name = strdup(args); +#endif } @@ -222,7 +242,11 @@ tlog3b_xgcb_tfdes(xg_string args, const QXmlStreamAttributes* unused) xmltrk = route_head_alloc(); track_add_head(xmltrk); } +#if NEW_STRINGS + xmltrk->rte_desc = args; +#else xmltrk->rte_desc = strdup(args); +#endif } @@ -259,9 +283,13 @@ tlog3b_xgcb_tpten(xg_string args, const QXmlStreamAttributes* unused) static void tlog3b_xgcb_wptid(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + xmlwpt->shortname = args; +#else if (*args) { xmlwpt->shortname = xstrdup(args); } +#endif } @@ -275,6 +303,8 @@ tlog3b_xgcb_wptdt(xg_string args, const QXmlStreamAttributes* unused) static void tlog3b_xgcb_wptgr(xg_string args, const QXmlStreamAttributes* unused) { + xmlgrid = args; +/* if (xmlgrid != NULL) { if (strcmp(xmlgrid, args) == 0) { return; @@ -282,27 +312,40 @@ tlog3b_xgcb_wptgr(xg_string args, const QXmlStreamAttributes* unused) xfree(xmlgrid); } xmlgrid = xstrdup(args); +*/ } static void tlog3b_xgcb_wptno(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + xmlNorthing = args.toDouble(); +#else xmlNorthing = atof(args); +#endif } static void tlog3b_xgcb_wptea(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + xmlEasting = args.toDouble(); +#else xmlEasting = atof(args); +#endif } static void tlog3b_xgcb_wptal(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + xmlAltitude = args.toDouble(); +#else xmlAltitude = atof(args); +#endif } @@ -367,6 +410,12 @@ write_str(const char* str, gbfile* f) } } +static void +write_str(const QString& str, gbfile* f) +{ + write_str(CSTR(str), f); +} + static int read_datum(gbfile* f) { @@ -661,16 +710,13 @@ dmtlog_rd_init(const char* fname) xmlbin = NULL; xmltrk = NULL; xmlwpt = NULL; - xmlgrid = NULL; + xmlgrid = QString(); } static void dmtlog_rd_deinit(void) { gbfclose(fin); - if (xmlgrid != NULL) { - xfree(xmlgrid); - } } static void @@ -728,7 +774,15 @@ write_header(const route_head* trk) queue* curr, *prev; QUEUE_FOR_EACH(&trk->waypoint_list, curr, prev) count++; } +#if NEW_STRINGS + if (!trk || trk->rte_name.isEmpty()) { + write_str("Name", fout); + } else { + write_str(trk->rte_name, fout); + } +#else write_str(trk && trk->rte_name && *trk->rte_name ? CSTRc(trk->rte_name) : "Name", fout); +#endif xasprintf(&cout, "%d trackpoints and %d waypoints", count, waypt_count()); write_str(cout, fout); @@ -783,14 +837,22 @@ wpt_cb(const waypoint* wpt) gbfputdbl(wpt->altitude != unknown_alt ? wpt->altitude : 0, fout); names = 1; +#if NEW_STRINGS + if (!wpt->description.isEmpty()) { +#else if (wpt->description && *wpt->description) { +#endif names = 2; } gbfputint32(names, fout); if (names > 1) { write_str(wpt->description, fout); } +#if NEW_STRINGS + write_str(wpt->shortname.isEmpty() ? "Name" : wpt->shortname, fout); +#else write_str(wpt->shortname && *wpt->shortname ? CSTRc(wpt->shortname) : "Name", fout); +#endif } static void diff --git a/gpsbabel/duplicate.cc b/gpsbabel/duplicate.cc index bca2779ad..d723a5040 100644 --- a/gpsbabel/duplicate.cc +++ b/gpsbabel/duplicate.cc @@ -207,7 +207,7 @@ duplicate_process(void) memset(&dupe, '\0', sizeof(dupe)); if (snopt) { - strncpy(dupe.shortname, waypointp->shortname, sizeof(dupe.shortname) - 1); + strncpy(dupe.shortname, CSTRc(waypointp->shortname), sizeof(dupe.shortname) - 1); } if (lcopt) { diff --git a/gpsbabel/easygps.cc b/gpsbabel/easygps.cc index 34f193f68..8270e22e5 100644 --- a/gpsbabel/easygps.cc +++ b/gpsbabel/easygps.cc @@ -168,12 +168,19 @@ static void ez_disp(const waypoint* wpt) { gbfputc('W', file_out); - +#if NEW_STRINGS + if (!wpt->shortname.isEmpty()) { +#else if (wpt->shortname) { +#endif gbfputc(1, file_out); gbfputpstr(wpt->shortname, file_out); } +#if NEW_STRINGS + if (!wpt->description.isEmpty()) { +#else if (wpt->description) { +#endif gbfputc(3, file_out); gbfputpstr(wpt->description, file_out); } @@ -186,8 +193,11 @@ ez_disp(const waypoint* wpt) gbfputc(0x64, file_out); gbfputdbl(wpt->longitude, file_out); - +#if NEW_STRINGS + if (!wpt->notes.isEmpty()) { +#else if (wpt->notes) { +#endif gbfputc(5, file_out); gbfputpstr(wpt->notes, file_out); } diff --git a/gpsbabel/exif.cc b/gpsbabel/exif.cc index f449ffbc3..6c9f9396e 100644 --- a/gpsbabel/exif.cc +++ b/gpsbabel/exif.cc @@ -892,11 +892,14 @@ exif_waypt_from_exif_app(exif_app_t* app) if (((c = strchr(cx, '.'))) && (c != cx)) { *c = '\0'; } - +#if NEW_STRINGS + wpt->shortname = cx; +#else if (wpt->shortname) { xfree(wpt->shortname); } wpt->shortname = xstrdup(cx); +#endif xfree(str); } diff --git a/gpsbabel/g7towin.cc b/gpsbabel/g7towin.cc index 01292f6ad..fa25e7f90 100644 --- a/gpsbabel/g7towin.cc +++ b/gpsbabel/g7towin.cc @@ -129,10 +129,14 @@ parse_line(char* buff, int index, const char* delimiter, waypoint* wpt) case WPT_cA_OFS + 1: case WPT_c1_OFS + 1: +#if NEW_STRINGS + wpt->shortname = cin; +#else if (wpt->shortname) { xfree(wpt->shortname); } wpt->shortname = xstrdup(cin); +#endif break; case WPT_cA_OFS + 4: diff --git a/gpsbabel/garmin_device_xml.cc b/gpsbabel/garmin_device_xml.cc index 84348bfce..a40fc0dab 100644 --- a/gpsbabel/garmin_device_xml.cc +++ b/gpsbabel/garmin_device_xml.cc @@ -40,7 +40,11 @@ jmp_buf gdx_jmp_buf; void type_s(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + type = args.compare("GPSData"); +#else type = strcmp(args, "GPSData"); +#endif } void device_s(xg_string args, const QXmlStreamAttributes* unused) @@ -77,7 +81,11 @@ void dir_s(xg_string args, const QXmlStreamAttributes* unused) if (type) { return; } +#if NEW_STRINGS + if ((args == "OutputFromUnit")) { +#else if (0 == strcmp(args, "OutputFromUnit")) { +#endif xasprintf(&my_gdx_info->from_device.path, "%s%c%s", mountpoint, GB_PATHSEP, path); my_gdx_info->from_device.basename = xstrdup(base); @@ -86,13 +94,17 @@ void dir_s(xg_string args, const QXmlStreamAttributes* unused) my_gdx_info->from_device.path, my_gdx_info->from_device.basename, my_gdx_info->from_device.extension); +#if NEW_STRINGS + } if ((args == "InputToUnit")) { +#else } else if (0 == strcmp(args, "InputToUnit")) { +#endif xasprintf(&my_gdx_info->to_device.path, "%s%c%s", mountpoint, GB_PATHSEP, path); my_gdx_info->to_device.basename = xstrdup(base); my_gdx_info->to_device.extension = xstrdup(ext); } else { - fatal(MYNAME ":Unknown direction '%s'\n", args); + fatal(MYNAME ":Unknown direction '%s'\n", CSTRc(args)); } if (base) { diff --git a/gpsbabel/garmin_gpi.cc b/gpsbabel/garmin_gpi.cc index 83e1ec428..a5342c5b9 100644 --- a/gpsbabel/garmin_gpi.cc +++ b/gpsbabel/garmin_gpi.cc @@ -384,7 +384,11 @@ read_poi(const int sz, const int tag) (void) gbfgetint16(fin); /* ? always 1 ? */ (void) gbfgetc(fin); /* seems to 1 when extra options present */ +#if NEW_STRINGS + wpt->shortname = QString::fromLatin1(gpi_read_string("Shortname")); +#else wpt->shortname = gpi_read_string("Shortname"); +#endif while (gbftell(fin) < (gbsize_t)(pos + sz - 4)) { int tag = gbfgetint32(fin); @@ -392,13 +396,21 @@ read_poi(const int sz, const int tag) break; } } - +#if NEW_STRINGS + if (wpt->description.isEmpty() && !wpt->notes.isEmpty()) { + wpt->description = wpt->notes; + } + if (wpt->notes.isEmpty() && !wpt->description.isEmpty()) { + wpt->notes = wpt->description; + } +#else if (wpt->notes && !wpt->description) { wpt->description = xstrdup(wpt->notes); } if (wpt->description && !wpt->notes) { wpt->notes = xstrdup(wpt->description); } +#endif waypt_add(wpt); @@ -526,17 +538,27 @@ read_tag(const char* caller, const int tag, waypoint* wpt) /* speed isn't part of a normal waypoint WAYPT_SET(wpt, speed, speed); */ +#if NEW_STRINGS + if ((wpt->shortname.isEmpty() || (wpt->shortname).indexOf('@'))) { +#else if ((wpt->shortname == NULL) || (! strchr(wpt->shortname, '@'))) { +#endif if (units == 's') { speed = MPS_TO_MPH(speed); } else { speed = MPS_TO_KPH(speed); } +#if NEW_STRINGS +// double check + QString base = wpt->shortname.isEmpty() ? "WPT" : wpt->shortname; + wpt->shortname = base + QString("@.%1").arg(speed); +#else xasprintf(&str, "%s@%.f", wpt->shortname ? CSTRc(wpt->shortname) : "WPT", speed); if (wpt->shortname) { xfree(wpt->shortname); } wpt->shortname = str; +#endif } } @@ -577,10 +599,18 @@ read_tag(const char* caller, const int tag, waypoint* wpt) break; } +#if NEW_STRINGS + if (!wpt->description.isEmpty()) { +#else if (wpt->description) { +#endif wpt->notes = str; } else { +#if NEW_STRINGS + wpt->description = QString::fromLatin1(str); +#else wpt->description = str; +#endif } break; @@ -722,17 +752,32 @@ write_string(const char* str, const char long_format) gbfwrite(str, 1, len, fout); } +static void +write_string(const QString& str, const char long_format) +{ + write_string(CSTR(str), long_format); +} + static int compare_wpt_cb(const queue* a, const queue* b) { const waypoint* wa = (waypoint*) a; const waypoint* wb = (waypoint*) b; - +#if NEW_STRINGS + return wa->shortname.compare(wb->shortname); +#else return strcmp(wa->shortname, wb->shortname); +#endif } +static char +compare_strings(const QString& s1, const QString& s2) +{ + return s1.compare(s2); +} +#if !NEW_STRINGS static char compare_strings(const char* s1, const char* s2) { @@ -748,6 +793,7 @@ compare_strings(const char* s1, const char* s2) return 1; } } +#endif static writer_data_t* @@ -889,11 +935,15 @@ wdata_compute_size(writer_data_t* data) waypoint* wpt = (waypoint*) elem; gpi_waypt_t* dt; garmin_fs_t* gmsd; - char* str; + QString str; res += 12; /* tag/sz/sub-sz */ res += 19; /* poi fixed size */ +#if NEW_STRINGS + res += wpt->shortname.length(); +#else res += strlen(wpt->shortname); +#endif if (! opt_hide_bitmap) { res += 10; /* tag(4) */ } @@ -903,8 +953,13 @@ wdata_compute_size(writer_data_t* data) if (alerts) { char* pos; - +#if NEW_STRINGS +// examine closely. + QString t = wpt->shortname.mid(wpt->shortname.indexOf('@')); + if ((pos = xstrdup(CSTR(t)))) { +#else if ((pos = strchr(wpt->shortname, '@'))) { +#endif double speed, scale; if (units == 's') { scale = MPH_TO_MPS(1); @@ -936,13 +991,21 @@ wdata_compute_size(writer_data_t* data) } } - str = NULL; + str = QString(); if (opt_descr) { +#if NEW_STRINGS + if (!wpt->description.isEmpty()) { +#else if (wpt->description && *wpt->description) { +#endif str = xstrdup(wpt->description); } } else if (opt_notes) { +#if NEW_STRINGS + if (!wpt->notes.isEmpty()) { +#else if (wpt->notes && *wpt->notes) { +#endif str = xstrdup(wpt->notes); } } else if (opt_pos) { @@ -950,9 +1013,9 @@ wdata_compute_size(writer_data_t* data) } - if (str) { + if (!str.isEmpty()) { dt->addr_is_dynamic = 1; - dt->addr = str; + dt->addr = xstrdup(CSTR(str)); dt->mask |= GPI_ADDR_ADDR; dt->sz += (8 + strlen(dt->addr)); } @@ -991,12 +1054,12 @@ wdata_compute_size(writer_data_t* data) } str = wpt->description; - if (! str) { + if (str.isEmpty()) { str = wpt->notes; } // if (str && (strcmp(str, wpt->shortname) == 0)) str = NULL; - if (str) { - res += (12 + 4 + strlen(str)); + if (!str.isEmpty()) { + res += (12 + 4 + str.length()); } } @@ -1038,25 +1101,28 @@ wdata_write(const writer_data_t* data) gbfputc(data->alert, fout); QUEUE_FOR_EACH(&data->Q, elem, tmp) { - char* str; + QString str; int s0, s1; waypoint* wpt = (waypoint*)elem; gpi_waypt_t* dt = (gpi_waypt_t*) wpt->extra_data; str = wpt->description; - if (! str) { + if (str.isEmpty()) { str = wpt->notes; } // if (str && (strcmp(str, wpt->shortname) == 0)) str = NULL; gbfputint32(0x80002, fout); - +#if NEW_STRINGS + s0 = s1 = 19 + wpt->shortname.length(); +#else s0 = s1 = 19 + strlen(wpt->shortname); +#endif if (! opt_hide_bitmap) { s0 += 10; /* tag(4) */ } - if (str) { - s0 += (12 + 4 + strlen(str)); /* descr */ + if (!str.isEmpty()) { + s0 += (12 + 4 + str.length()); /* descr */ } if (dt->sz) { s0 += (12 + dt->sz); /* address part */ @@ -1111,9 +1177,9 @@ wdata_write(const writer_data_t* data) gbfputint16(0, fout); } - if (str) { + if (!str.isEmpty()) { gbfputint32(0xa, fout); - gbfputint32(strlen(str) + 8, fout); /* string + string header */ + gbfputint32(str.length() + 8, fout); /* string + string header */ write_string(str, 1); } @@ -1227,7 +1293,6 @@ static void enum_waypt_cb(const waypoint* ref) { waypoint* wpt; - char* str; queue* elem, *tmp; QUEUE_FOR_EACH(&wdata->Q, elem, tmp) { @@ -1245,10 +1310,15 @@ enum_waypt_cb(const waypoint* ref) wpt = waypt_dupe(ref); + QString str; if (*opt_unique == '1') { str = mkshort(short_h, wpt->shortname); +#if NEW_STRINGS + wpt->shortname = str; +#else xfree(wpt->shortname); wpt->shortname = str; +#endif } wdata_add_wpt(wdata, wpt); diff --git a/gpsbabel/garmin_tables.cc b/gpsbabel/garmin_tables.cc index 855ebd682..d0f85a701 100644 --- a/gpsbabel/garmin_tables.cc +++ b/gpsbabel/garmin_tables.cc @@ -866,18 +866,19 @@ int gt_find_icon_number_from_desc(const QString& desc, garmin_formats_e garmin_f } const char* -gt_get_icao_country(const char* cc) +gt_get_icao_country(const QString& cc) { gt_country_code_t* x = >_country_codes[0]; - if ((cc == NULL) || (*cc == '\0')) { + if (cc.isEmpty()) { return NULL; } do { const char* ccx = x->cc; + const QString qccx = x->cc; while (ccx != NULL) { - if (strncmp(ccx, cc, 2) == 0) { + if (qccx.left(2) == cc) { return x->country; } if ((ccx[0] == cc[0]) && (ccx[1] == '*')) { @@ -895,22 +896,22 @@ gt_get_icao_country(const char* cc) } const char* -gt_get_icao_cc(const char* country, const char* shortname) +gt_get_icao_cc(const QString& country, const QString& shortname) { static char res[3]; gt_country_code_t* x = >_country_codes[0]; - if ((country == NULL) || (*country == '\0')) { + if (country.isEmpty()) { const char* test; if (shortname == NULL) { return NULL; } - switch (strlen(shortname)) { + switch (shortname.length()) { case 3: - strncpy(res, shortname, 1); + strncpy(res, CSTR(shortname), 1); break; case 4: - strncpy(res, shortname, 2); + strncpy(res, CSTR(shortname), 2); break; default: return NULL; @@ -924,7 +925,7 @@ gt_get_icao_cc(const char* country, const char* shortname) } do { - if (case_ignore_strcmp(country, x->country) != 0) { + if (country.compare(x->country, Qt::CaseInsensitive) != 0) { x++; continue; } @@ -938,10 +939,10 @@ gt_get_icao_cc(const char* country, const char* shortname) } return res; } - if (shortname && (strlen(shortname) == 4)) { + if (shortname.length() == 4) { const char* ccx = x->cc; - strncpy(res, shortname, 2); + strncpy(res, CSTR(shortname), 2); res[2] = '\0'; while (ccx != NULL) { if (strncmp(ccx, res, 2) == 0) { diff --git a/gpsbabel/garmin_tables.h b/gpsbabel/garmin_tables.h index 08f21e492..4be38ee7a 100644 --- a/gpsbabel/garmin_tables.h +++ b/gpsbabel/garmin_tables.h @@ -66,8 +66,8 @@ typedef struct gt_country_code_s { extern gt_country_code_t gt_country_codes[]; -const char* gt_get_icao_country(const char* cc); -const char* gt_get_icao_cc(const char* country, const char* shortname); +const char* gt_get_icao_country(const QString& cc); +const char* gt_get_icao_cc(const QString& country, const QString& shortname); /* this order is used by most devices */ typedef enum { diff --git a/gpsbabel/garmin_txt.cc b/gpsbabel/garmin_txt.cc index e1320f50c..d4507704c 100644 --- a/gpsbabel/garmin_txt.cc +++ b/gpsbabel/garmin_txt.cc @@ -226,8 +226,11 @@ sort_waypt_cb(const void* a, const void* b) { const waypoint* wa = *(waypoint**)a; const waypoint* wb = *(waypoint**)b; - +#if NEW_STRINGS + return wa->shortname.compare(wb->shortname, Qt::CaseInsensitive); +#else return case_ignore_strcmp(QString::fromLatin1(wa->shortname), QString::fromLatin1(wb->shortname)); +#endif } @@ -351,7 +354,11 @@ print_position(const waypoint* wpt) if (! valid) { gbfprintf(fout, "#####\n"); fatal(MYNAME ": %s (%s) is outside of convertable area \"%s\"!\n", +#if NEW_STRINGS + wpt->shortname.isEmpty() ? "Waypoint" : CSTR(wpt->shortname), +#else wpt->shortname ? CSTRc(wpt->shortname) : "Waypoint", +#endif pretty_deg_format(wpt->latitude, wpt->longitude, 'd', NULL, 0), gt_get_mps_grid_longname(grid_index, MYNAME)); } @@ -559,11 +566,19 @@ write_waypt(const waypoint* wpt) wpt_type = gt_waypt_class_names[0]; } +#if NEW_STRINGS + gbfprintf(fout, "Waypoint\t%s\t", CSTRc(wpt->shortname)); +#else gbfprintf(fout, "Waypoint\t%s\t", (wpt->shortname) ? CSTRc(wpt->shortname) : ""); +#endif if (wpt_class <= gt_waypt_class_airport_ndb) { - const char* temp = wpt->notes; - if (temp == NULL) { + QString temp = wpt->notes; + if (temp.isEmpty()) { +#if NEW_STRINGS + if (wpt->description != wpt->shortname) { +#else if (wpt->description && (strcmp(wpt->description, wpt->shortname) != 0)) { +#endif temp = wpt->description; } else { temp = ""; @@ -645,8 +660,11 @@ route_disp_hdr_cb(const route_head* rte) gtxt_flags.route_header_written = 1; gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[route_header]); } - +#if NEW_STRINGS + print_string("\r\nRoute\t%s\t", current_trk->rte_name); +#else print_string("\r\nRoute\t%s\t", current_trk->rte_name ? CSTRc(current_trk->rte_name) : ""); +#endif print_distance(cur_info->length, 0, 1, 0); print_course(cur_info->first_wpt, cur_info->last_wpt); gbfprintf(fout, "\t%d waypoints\t", cur_info->count); @@ -698,8 +716,11 @@ track_disp_hdr_cb(const route_head* track) gtxt_flags.track_header_written = 1; gbfprintf(fout, "\r\n\r\nHeader\t%s\r\n", headers[track_header]); } - +#if NEW_STRINGS + print_string("\r\nTrack\t%s\t", current_trk->rte_name); +#else print_string("\r\nTrack\t%s\t", current_trk->rte_name ? CSTRc(current_trk->rte_name) : ""); +#endif print_date_and_time(cur_info->start, 0); print_date_and_time(cur_info->time, 1); print_distance(cur_info->length, 0, 1, 0); diff --git a/gpsbabel/glogbook.cc b/gpsbabel/glogbook.cc index fc7e0d0d7..e51120fc8 100644 --- a/gpsbabel/glogbook.cc +++ b/gpsbabel/glogbook.cc @@ -168,17 +168,29 @@ void gl_trk_utc(xg_string args, const QXmlStreamAttributes* unused) void gl_trk_lat(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->latitude = args.toDouble(); +#else wpt_tmp->latitude = atof(args); +#endif } void gl_trk_long(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->longitude = args.toDouble(); +#else wpt_tmp->longitude = atof(args); +#endif } void gl_trk_alt(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->altitude = args.toDouble(); +#else wpt_tmp->altitude = atof(args); +#endif } diff --git a/gpsbabel/google.cc b/gpsbabel/google.cc index 98454292b..c831202b0 100644 --- a/gpsbabel/google.cc +++ b/gpsbabel/google.cc @@ -34,7 +34,6 @@ static const char* rd_fname; static int serial = 0; #define MYNAME "google" -#define MY_CBUF 4096 static xg_callback goog_points, goog_levels, goog_poly_e, goog_script; static xg_callback goog_segment_s, goog_segment, goog_td_s, goog_td_b; @@ -59,9 +58,13 @@ xg_tag_mapping google_map[] = { void goog_script(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + if (true) { +#else if (args) { +#endif if (script) { - script = xstrappend(script, args); + script = xstrappend(script, CSTRc(args)); } else { script = xstrdup(args); } @@ -70,9 +73,13 @@ void goog_script(xg_string args, const QXmlStreamAttributes* unused) void goog_points(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + if (true) { +#else if (args) { +#endif if (encoded_points) { - encoded_points = xstrappend(encoded_points, args); + encoded_points = xstrappend(encoded_points, CSTRc(args)); } else { encoded_points = xstrdup(args); } @@ -81,9 +88,13 @@ void goog_points(xg_string args, const QXmlStreamAttributes* unused) void goog_levels(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + if (true) { +#else if (args) { +#endif if (encoded_levels) { - encoded_levels = xstrappend(encoded_levels, args); + encoded_levels = xstrappend(encoded_levels, CSTRc(args)); } else { encoded_levels = xstrdup(args); } @@ -113,8 +124,11 @@ void goog_segment(xg_string args, const QXmlStreamAttributes* unused) wpt_tmp = route_find_waypt_by_name(routehead[goog_segroute], goog_segname); if (wpt_tmp) { +#if NEW_STRINGS +#else xfree(wpt_tmp->shortname); - wpt_tmp->shortname = mkshort(desc_handle, args); +#endif + wpt_tmp->shortname = mkshort(desc_handle, CSTRc(args)); wpt_tmp->description = xstrdup(args); } } @@ -157,13 +171,13 @@ void goog_td_s(xg_string args, const QXmlStreamAttributes* attrv) void goog_td_b(xg_string args, const QXmlStreamAttributes* unused) { - if (goog_segname[0] == '\\' && !strchr(args, '\xa0')) { + if (goog_segname[0] == '\\' && !strchr(CSTRc(args), '\xa0')) { if (goog_realname) { xfree(goog_realname); goog_realname = NULL; } - goog_realname = (char*) xmalloc(strlen(args)+1); - strcpy(goog_realname, args); + goog_realname = (char*) xmalloc(strlen(CSTRc(args))+1); + strcpy(goog_realname, CSTRc(args)); } } void goog_td_e(xg_string args, const QXmlStreamAttributes* unused) @@ -238,7 +252,11 @@ void goog_poly_e(xg_string args, const QXmlStreamAttributes* unused) wpt_tmp->longitude = lon / 100000.0; wpt_tmp->route_priority=level; wpt_tmp->shortname = (char*) xmalloc(7); +#if NEW_STRINGS + wpt_tmp->shortname = QString().sprintf( "\\%5.5x", serial++); +#else sprintf(wpt_tmp->shortname, "\\%5.5x", serial++); +#endif route_add_wpt(routehead[goog_segroute], wpt_tmp); } } diff --git a/gpsbabel/googledir.cc b/gpsbabel/googledir.cc index 48ddb34d1..8f10e2e2a 100644 --- a/gpsbabel/googledir.cc +++ b/gpsbabel/googledir.cc @@ -30,8 +30,8 @@ #include "defs.h" #include "xmlgeneric.h" -static char* encoded_points = NULL; -static char* instructions = NULL; +static QString encoded_points; +static QString instructions; static short_handle desc_handle; #define MYNAME "googledir" @@ -53,25 +53,13 @@ xg_tag_mapping google_map[] = { void goog_points(xg_string args, const QXmlStreamAttributes* unused) { - if (args) { - if (encoded_points) { - encoded_points = xstrappend(encoded_points, args); - } else { - encoded_points = xstrdup(args); - } - } + encoded_points += args; } void goog_instr(xg_string args, const QXmlStreamAttributes* unused) { - if (args) { - if (instructions) { - instructions = xstrappend(instructions, args); - } else { - instructions = xstrdup(args); - } - } + instructions += args; } static int goog_step = 0; @@ -104,10 +92,16 @@ goog_poly_e(xg_string args, const QXmlStreamAttributes* unused) { long lat = 0; long lon = 0; - char* str = encoded_points; +//NEW_STRINGS. Kind of silly to make a copy here. + char* ostr = xstrdup(encoded_points); + char* str = ostr; route_head* routehead = route_head_alloc(); +#if NEW_STRINGS + if (args == "overview_polyline") { +#else if (strcmp(args, "overview_polyline") == 0) { +#endif routehead->rte_name = (char*) xstrdup("overview"); routehead->rte_desc = (char*) xstrdup("Overview"); } else { @@ -118,10 +112,9 @@ goog_poly_e(xg_string args, const QXmlStreamAttributes* unused) } else { utf_string utf; utf.is_html = 1; - utf.utfstring = QString::fromUtf8(instructions); + utf.utfstring = /*QString::fromUtf8*/(instructions); routehead->rte_desc = strip_html(&utf); - xfree(instructions); - instructions = NULL; + instructions = QString(); } } route_add_head(routehead); @@ -140,15 +133,9 @@ goog_poly_e(xg_string args, const QXmlStreamAttributes* unused) route_add_wpt(routehead, wpt_tmp); } } - - if (encoded_points) { - xfree(encoded_points); - encoded_points = NULL; - } - if (instructions) { - xfree(instructions); - instructions = NULL; - } +xfree(ostr); + encoded_points = QString(); + instructions = QString(); } static void @@ -166,14 +153,8 @@ google_read(void) { xml_read(); - if (encoded_points) { - xfree(encoded_points); - encoded_points = NULL; - } - if (instructions) { - xfree(instructions); - instructions = NULL; - } + encoded_points = QString(); + instructions = QString(); } static void diff --git a/gpsbabel/gpsutil.cc b/gpsbabel/gpsutil.cc index f06825460..9deedfde7 100644 --- a/gpsbabel/gpsutil.cc +++ b/gpsbabel/gpsutil.cc @@ -148,8 +148,8 @@ gpsutil_disp(const waypoint* wpt) gbfprintf(file_out, "%-8.8s %08.3f%c %09.3f%c %07.0f%c %-30.30s %s\n", global_opts.synthesize_shortnames ? - mkshort_from_wpt(mkshort_handle, wpt) : - wpt->shortname, + CSTRc(mkshort_from_wpt(mkshort_handle, wpt)) : + CSTRc(wpt->shortname), fabs(lat), lat < 0.0 ? 'S' : 'N', fabs(lon), @@ -157,7 +157,7 @@ gpsutil_disp(const waypoint* wpt) ((wpt->altitude == unknown_alt) || (wpt->altitude < 0.0)) ? 0 : wpt->altitude, 'm', - wpt->description ? tdesc : "", + CSTRc(wpt->description) ? tdesc : "", icon_token.toUtf8().data()); xfree(tdesc); diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index 818644105..532bb6137 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -623,12 +623,18 @@ tag_log_wpt(const QXmlStreamAttributes& attr) we need to keep track of log_wpt counts so we don't collide with dupe shortnames. */ +#if NEW_STRINGS + if (wpt_tmp->shortname.size() > 2) { +// FIXME: think harder about this later. + lwp_tmp->shortname = wpt_tmp->shortname.mid(2, 4) + "-FIXME"; + +#else if ((wpt_tmp->shortname) && (strlen(wpt_tmp->shortname) > 2)) { /* copy of the shortname */ lwp_tmp->shortname = (char*) xcalloc(7, 1); sprintf(lwp_tmp->shortname, "%-4.4s%02d", &wpt_tmp->shortname[2], logpoint_ct++); - +#endif waypt_add(lwp_tmp); } } @@ -932,10 +938,14 @@ gpx_end(const QString& el) wpt_tmp = NULL; break; case tt_cache_name: +#if NEW_STRINGS + wpt_tmp->notes = cdatastr; +#else if (wpt_tmp->notes != NULL) { xfree(wpt_tmp->notes); } wpt_tmp->notes = xstrdup(cdatastr); +#endif break; case tt_cache_container: waypt_alloc_gc_data(wpt_tmp)->container = gs_mkcont(cdatastr); @@ -1116,10 +1126,14 @@ gpx_end(const QString& el) case tt_wpt_desc: case tt_trk_trkseg_trkpt_desc: case tt_rte_rtept_desc: +#if NEW_STRINGS + wpt_tmp->notes = cdatastr; +#else if (wpt_tmp->notes != NULL) { xfree(wpt_tmp->notes); } wpt_tmp->notes = xstrdup(cdatastr); +#endif break; case tt_pdop: wpt_tmp->pdop = cdatastr.toDouble(); @@ -1603,8 +1617,13 @@ gpx_track_hdr(const route_head* rte) current_trk_head = rte; writer->writeStartElement("trk"); +#if NEW_STRINGS + writer->writeOptionalTextElement("name", rte->rte_name); + writer->writeOptionalTextElement("desc", rte->rte_desc); +#else writer->writeOptionalTextElement("name", QString::fromUtf8(rte->rte_name)); writer->writeOptionalTextElement("desc", QString::fromUtf8(rte->rte_desc)); +#endif if (rte->rte_num) { writer->writeTextElement("number", QString::number(rte->rte_num)); } @@ -1622,7 +1641,6 @@ gpx_track_hdr(const route_head* rte) static void gpx_track_disp(const waypoint* waypointp) { - const char* oname; fs_xml* fs_gpx; int first_in_trk; first_in_trk = waypointp->Q.prev == ¤t_trk_head->waypoint_list; @@ -1653,6 +1671,11 @@ gpx_track_disp(const waypoint* waypointp) /* GPX doesn't require a name on output, so if we made one up * on input, we might as well say nothing. */ +#if NEW_STRINGS + QString oname; +#else + const char* oname; +#endif oname = global_opts.synthesize_shortnames ? mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname; @@ -1715,7 +1738,11 @@ gpx_route_hdr(const route_head* rte) static void gpx_route_disp(const waypoint* waypointp) { +#if NEW_STRINGS + QString oname; +#else const char* oname; +#endif fs_xml* fs_gpx; writer->writeStartElement("rtept"); writer->writeAttribute("lat", toString(waypointp->latitude)); diff --git a/gpsbabel/gtrnctr.cc b/gpsbabel/gtrnctr.cc index 5e6d5ce85..a0f75836d 100644 --- a/gpsbabel/gtrnctr.cc +++ b/gpsbabel/gtrnctr.cc @@ -226,6 +226,21 @@ gtc_write_xml(int indent, const char* fmt, ...) va_end(args); } +static void +gtc_write_xml(int indent, const QString s) +{ + if (indent < 0) { + gtc_indent_level--; + } + gbfprintf(ofd, "%*s", gtc_indent_level * 2, ""); + gbfputs(s, ofd); + if (indent > 0) { + gtc_indent_level++; + } + + +} + static void gtc_lap_start(const route_head* rte) { @@ -401,10 +416,16 @@ gtc_crs_hdr(const route_head* rte) gtc_lap_start(NULL); gtc_new_study_lap(rte); route_disp(rte, gtc_study_lap); +#if NEW_STRINGS + if (!rte->rte_name.isEmpty()) { + QString name = rte->rte_name.left(GTC_MAX_NAME_LEN); + gtc_write_xml(0, QString("%1\n").arg(name)); +#else if (rte->rte_name) { char* name = xstrndup(rte->rte_name, GTC_MAX_NAME_LEN); gtc_write_xml(0, "%s\n", name); xfree(name); +#endif } else { gtc_write_xml(0, "New Course\n"); } @@ -444,7 +465,7 @@ gtc_write(void) } void -gtc_trk_s(const char* unused, const QXmlStreamAttributes* unusedattrs) +gtc_trk_s(const xg_string unused, const QXmlStreamAttributes* unusedattrs) { trk_head = route_head_alloc(); track_add_head(trk_head); @@ -457,26 +478,26 @@ gtc_trk_ident(xg_string args, const QXmlStreamAttributes* unused) } void -gtc_trk_lap_s(const char* unused, const QXmlStreamAttributes* unusedattrs) +gtc_trk_lap_s(xg_string unused, const QXmlStreamAttributes* unusedattrs) { lap_ct++; lap_s = 1; } void -gtc_trk_lap_e(const char* unused, const QXmlStreamAttributes* unusedattrs) +gtc_trk_lap_e(xg_string unused, const QXmlStreamAttributes* unusedattrs) { lap_s = 0; } void -gtc_trk_pnt_s(const char* unused, const QXmlStreamAttributes* unusedattrs) +gtc_trk_pnt_s(xg_string unused, const QXmlStreamAttributes* unusedattrs) { wpt_tmp = waypt_new(); } void -gtc_trk_pnt_e(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_trk_pnt_e(xg_string args, const QXmlStreamAttributes* unused) { if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) { if (lap_s) { @@ -499,67 +520,117 @@ gtc_trk_pnt_e(xg_string args, const QXmlStreamAttributes* unusedd) } void -gtc_trk_utc(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_trk_utc(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->creation_time = xml_parse_time(args); } void -gtc_trk_lat(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_trk_lat(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->latitude = args.toDouble(); +#else wpt_tmp->latitude = atof(args); +#endif } void -gtc_trk_long(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_trk_long(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->longitude = args.toDouble(); +#else wpt_tmp->longitude = atof(args); +#endif } +#if NEW_STRINGS +void +gtc_trk_alt(xg_string args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->altitude = args.toDouble(); +} +#else void -gtc_trk_alt(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_trk_alt(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->altitude = atof(args); } +#endif +#if NEW_STRINGS +void gtc_trk_dist(const QString& args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->odometer_distance = args.toDouble(); +} +void gtc_trk_hr(const QString& args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->heartrate = args.toDouble(); +} +void gtc_trk_cad(const QString& args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->cadence = args.toDouble(); +} +#else void -gtc_trk_dist(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_trk_dist(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->odometer_distance = atof(args); } void -gtc_trk_hr(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_trk_hr(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->heartrate = atoi(args); } void -gtc_trk_cad(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_trk_cad(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->cadence = atoi(args); } +#endif +#if NEW_STRINGS +void +gtc_trk_pwr(xg_string args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->power = args.toDouble(); +} +#else void -gtc_trk_pwr(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_trk_pwr(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->power = atof(args); } +#endif void -gtc_trk_spd(xg_string args, const QXmlStreamAttributes* unusedd) +#if NEW_STRINGS +gtc_trk_spd(xg_string args, const QXmlStreamAttributes* unused) +{ + WAYPT_SET(wpt_tmp, speed, args.toDouble()); +} +#else +gtc_trk_spd(xg_string args, const QXmlStreamAttributes* unused) { WAYPT_SET(wpt_tmp, speed, atof(args)); } +#endif void +#if NEW_STRINGS +gtc_wpt_crs_s(const QString& args, const QXmlStreamAttributes* unused) +#else gtc_wpt_crs_s(const char* unused, const QXmlStreamAttributes* unusedattrs) +#endif { wpt_tmp = waypt_new(); } void -gtc_wpt_crs_e(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_wpt_crs_e(xg_string args, const QXmlStreamAttributes* unused) { if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) { waypt_add(wpt_tmp); @@ -571,14 +642,14 @@ gtc_wpt_crs_e(xg_string args, const QXmlStreamAttributes* unusedd) } void -gtc_wpt_pnt_s(const char* unused, const QXmlStreamAttributes* unusedattrs) +gtc_wpt_pnt_s(xg_string unused, const QXmlStreamAttributes* unusedattrs) { wpt_tmp = waypt_new(); lap_ct++; } void -gtc_wpt_pnt_e(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_wpt_pnt_e(xg_string args, const QXmlStreamAttributes* unused) { if (wpt_tmp->longitude != 0. && wpt_tmp->latitude != 0.) { /* Add the begin position of a CourseLap as @@ -594,8 +665,32 @@ gtc_wpt_pnt_e(xg_string args, const QXmlStreamAttributes* unusedd) wpt_tmp = NULL; } +#if NEW_STRINGS +void gtc_wpt_ident(const QString& args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->shortname = (args); + /* Set also as notes for compatibility with garmin usb format */ + wpt_tmp->notes = (args); +} +void gtc_wpt_lat(const QString& args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->latitude = args.toDouble(); +} +void gtc_wpt_long(const QString& args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->longitude = args.toDouble(); +} +void gtc_wpt_icon(const QString& args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->icon_descr = args; +} +void gtc_wpt_notes(const QString& args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->description = args; +} +#else void -gtc_wpt_ident(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_wpt_ident(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->shortname = xstrdup(args); /* Set also as notes for compatibility with garmin usb format */ @@ -603,28 +698,29 @@ gtc_wpt_ident(xg_string args, const QXmlStreamAttributes* unusedd) } void -gtc_wpt_lat(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_wpt_lat(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->latitude = atof(args); } void -gtc_wpt_long(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_wpt_long(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->longitude = atof(args); } void -gtc_wpt_icon(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_wpt_icon(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->icon_descr = args; } void -gtc_wpt_notes(xg_string args, const QXmlStreamAttributes* unusedd) +gtc_wpt_notes(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->description = xstrdup(args); } +#endif ff_vecs_t gtc_vecs = { ff_type_file, diff --git a/gpsbabel/hiketech.cc b/gpsbabel/hiketech.cc index 27f596ab0..1b14f65d0 100644 --- a/gpsbabel/hiketech.cc +++ b/gpsbabel/hiketech.cc @@ -212,19 +212,31 @@ void ht_sym(xg_string args, const QXmlStreamAttributes* unused) static void ht_lat(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->latitude = args.toDouble(); +#else wpt_tmp->latitude = atof(args); +#endif } static void ht_long(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->longitude = args.toDouble(); +#else wpt_tmp->longitude = atof(args); +#endif } static void ht_alt(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->altitude = args.toDouble(); +#else wpt_tmp->altitude = atof(args); +#endif } static @@ -271,7 +283,7 @@ void ht_trk_utc(xg_string args, const QXmlStreamAttributes* unused) struct tm tm; time_t utc; - sscanf(args, "%d-%d-%d %d:%d:%d", + sscanf(CSTRc(args), "%d-%d-%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec); @@ -287,19 +299,31 @@ void ht_trk_utc(xg_string args, const QXmlStreamAttributes* unused) static void ht_trk_lat(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->latitude = args.toDouble(); +#else wpt_tmp->latitude = atof(args); +#endif } static void ht_trk_long(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->longitude = args.toDouble(); +#else wpt_tmp->longitude = atof(args); +#endif } static void ht_trk_alt(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->altitude = args.toDouble(); +#else wpt_tmp->altitude = atof(args); +#endif } diff --git a/gpsbabel/holux.cc b/gpsbabel/holux.cc index 3572ae293..814106706 100644 --- a/gpsbabel/holux.cc +++ b/gpsbabel/holux.cc @@ -155,7 +155,7 @@ static void data_read(void) -char* mknshort(char* stIn,unsigned int sLen) +const char* mknshort(const char* stIn,unsigned int sLen) { #define MAX_STRINGLEN 255 static char strOut[MAX_STRINGLEN]; @@ -214,14 +214,14 @@ static void holux_disp(const waypoint* wpt) memset(pWptHxTmp->name,0x20,sizeof(pWptHxTmp->name)); if (wpt->shortname != NULL) { - strncpy(pWptHxTmp->name, mknshort(wpt->shortname,sizeof(pWptHxTmp->name)),sizeof(pWptHxTmp->name)); + strncpy(pWptHxTmp->name, mknshort(CSTRc(wpt->shortname),sizeof(pWptHxTmp->name)),sizeof(pWptHxTmp->name)); } else { sprintf(pWptHxTmp->name,"W%d",sIndex); } memset(pWptHxTmp->comment,0x20,sizeof(pWptHxTmp->comment)); if (wpt->description != NULL) { - strncpy(pWptHxTmp->comment, mknshort(wpt->description,sizeof(pWptHxTmp->comment)),sizeof(pWptHxTmp->comment)); + strncpy(pWptHxTmp->comment, mknshort(CSTRc(wpt->description),sizeof(pWptHxTmp->comment)),sizeof(pWptHxTmp->comment)); } /*set the time */ diff --git a/gpsbabel/html.cc b/gpsbabel/html.cc index 8ed540f41..46b538b40 100644 --- a/gpsbabel/html.cc +++ b/gpsbabel/html.cc @@ -92,7 +92,7 @@ html_disp(const waypoint* wpt) gbfprintf(file_out, "\n
\n", CSTRc(wpt->shortname)); gbfprintf(file_out, "\n"); - gbfprintf(file_out, "

%s - ",(global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname); + gbfprintf(file_out, "

%s - ",(global_opts.synthesize_shortnames) ? CSTRc(mkshort_from_wpt(mkshort_handle, wpt)) : CSTRc(wpt->shortname)); cout = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 1); gbfprintf(file_out, "%s (%d%c %6.0f %7.0f)", cout, utmz, utmzc, utme, utmn); xfree(cout); @@ -100,9 +100,13 @@ html_disp(const waypoint* wpt) gbfprintf(file_out, " alt:%d", (int)((altunits[0]=='f')?METERS_TO_FEET(wpt->altitude):wpt->altitude)); } gbfprintf(file_out, "
\n"); +#if NEW_STRINGS + if (wpt->description != wpt->shortname) { +#else if (strcmp(wpt->description, wpt->shortname)) { +#endif if (wpt->HasUrlLink()) { - char* d = html_entitize(wpt->description); + char* d = html_entitize(CSTRc(wpt->description)); UrlLink link = wpt->GetUrlLink(); gbfprintf(file_out, "%s", link.url_.toUtf8().data(), d); xfree(d); @@ -147,7 +151,11 @@ html_disp(const waypoint* wpt) } gbfprintf(file_out, "

Hint: %s

\n", hint); xfree(hint); +#if NEW_STRINGS + } else if (!wpt->notes.isEmpty() && (wpt->description.isEmpty() || wpt->notes != wpt->description)) { +#else } else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) { +#endif gbfprintf(file_out, "

%s

\n", CSTRc(wpt->notes)); } diff --git a/gpsbabel/humminbird.cc b/gpsbabel/humminbird.cc index 4e2b411ce..bfbdba4a7 100644 --- a/gpsbabel/humminbird.cc +++ b/gpsbabel/humminbird.cc @@ -682,7 +682,6 @@ humminbird_write_waypoint(const waypoint* wpt) double lat, north, east; int i; int num_icons = sizeof(humminbird_icons) / sizeof(humminbird_icons[0]); - char* name; be_write16(&hum.num, waypoint_num++); hum.zero = 0; @@ -725,12 +724,12 @@ humminbird_write_waypoint(const waypoint* wpt) north = inverse_gudermannian_i1924(lat); be_write32(&hum.north, si_round(north)); + QString name; name = (global_opts.synthesize_shortnames) ? mkshort_from_wpt(wptname_sh, wpt) : mkshort(wptname_sh, wpt->shortname); memset(&hum.name, 0, sizeof(hum.name)); - memcpy(&hum.name, name, strlen(name)); - xfree(name); + memcpy(&hum.name, CSTR(name), name.length()); gbfputuint32(WPT_MAGIC, fout); gbfwrite(&hum, sizeof(hum), 1, fout); @@ -751,13 +750,12 @@ humminbird_track_head(const route_head* trk) trk_head = NULL; last_time = 0; if (trk->rte_waypt_ct > 0) { - char* name; + QString name; trk_head = (humminbird_trk_header_t*) xcalloc(1, sizeof(humminbird_trk_header_t)); trk_points = (humminbird_trk_point_t*) xcalloc(max_points, sizeof(humminbird_trk_point_t)); name = mkshort(trkname_sh, trk->rte_name); - strncpy(trk_head->name, name, sizeof(trk_head->name)); - xfree(name); + strncpy(trk_head->name, CSTR(name), sizeof(trk_head->name)); be_write16(&trk_head->trk_num, trk->rte_num); } } @@ -893,7 +891,6 @@ humminbird_rte_tail(const route_head* rte) if (humrte->count > 0) { int i; - char* name; humrte->num = rte_num++; humrte->time = gpsbabel_time; @@ -904,9 +901,8 @@ humminbird_rte_tail(const route_head* rte) be_write16(&humrte->num, humrte->num); be_write32(&humrte->time, humrte->time); - name = mkshort(rtename_sh, rte->rte_name); - strncpy(humrte->name, name, sizeof(humrte->name)); - xfree(name); + QString name = mkshort(rtename_sh, rte->rte_name); + strncpy(humrte->name, CSTR(name), sizeof(humrte->name)); gbfputuint32(RTE_MAGIC, fout); gbfwrite(humrte, sizeof(*humrte), 1, fout); diff --git a/gpsbabel/ignrando.cc b/gpsbabel/ignrando.cc index 3b196c366..7e9efb77d 100644 --- a/gpsbabel/ignrando.cc +++ b/gpsbabel/ignrando.cc @@ -92,17 +92,25 @@ ignr_start(xg_string args, const QXmlStreamAttributes* attrv) static void ignr_nb_etapes(xg_string args, const QXmlStreamAttributes* attrv) { +#if NEW_STRINGS + xmlpoints = args.toInt(); +#else xmlpoints = atoi(args); +#endif } static void ignr_descr(xg_string args, const QXmlStreamAttributes* attrv) { ignr_xml_error((track == NULL)); - +#if NEW_STRINGS +qDebug() << args; + track->rte_desc = args; +#else if ((args != NULL) && (strlen(args) > 0)) { track->rte_desc = xstrdup(args); } +#endif } static void @@ -125,10 +133,14 @@ ignr_etape_end(xg_string args, const QXmlStreamAttributes* attrv) static void ignr_etape_pos(xg_string args, const QXmlStreamAttributes* attrv) { +#if NEW_STRINGS + ignr_xml_error((wpt == NULL) || (args.isEmpty())); +#else ignr_xml_error((wpt == NULL) || (args == NULL)); +#endif - if (2 != sscanf(args, "%lf,%lf", &wpt->latitude, &wpt->longitude)) { - fatal(MYNAME ": Invalid coordinates \"%s\"!\n", args); + if (2 != sscanf(CSTRc(args), "%lf,%lf", &wpt->latitude, &wpt->longitude)) { + fatal(MYNAME ": Invalid coordinates \"%s\"!\n", CSTRc(args)); } } @@ -140,8 +152,8 @@ ignr_etape_alt(xg_string args, const QXmlStreamAttributes* attrv) return; } - if (1 != sscanf(args, "%lf", &wpt->altitude)) { - fatal(MYNAME ": Invalid altitude \"%s\"!\n", args); + if (1 != sscanf(CSTRc(args), "%lf", &wpt->altitude)) { + fatal(MYNAME ": Invalid altitude \"%s\"!\n", CSTRc(args)); } } diff --git a/gpsbabel/ik3d.cc b/gpsbabel/ik3d.cc index 78337eef4..32f1cf81e 100644 --- a/gpsbabel/ik3d.cc +++ b/gpsbabel/ik3d.cc @@ -115,8 +115,11 @@ static void iktobj_type(xg_string args, const QXmlStreamAttributes* unused) { ikt_object_end(); - +#if NEW_STRINGS + switch (args.toInt()) { +#else switch (atoi(args)) { +#endif case 0: waypt = waypt_new(); break; @@ -124,7 +127,7 @@ iktobj_type(xg_string args, const QXmlStreamAttributes* unused) track = route_head_alloc(); break; default: - fatal(MYNAME ": Unknown object type %s!\n", args); + fatal(MYNAME ": Unknown object type %s!\n", CSTRc(args)); } } diff --git a/gpsbabel/interpolate.cc b/gpsbabel/interpolate.cc index 2f9a9b35d..918dfc439 100644 --- a/gpsbabel/interpolate.cc +++ b/gpsbabel/interpolate.cc @@ -99,6 +99,10 @@ interpfilt_process(void) timen += interval) { waypoint* wpt_new = waypt_dupe(wpt); wpt_new->SetCreationTime(timen); +#if NEW_STRINGS + wpt_new->shortname = QString(); + wpt_new->description = QString(); +#else if (wpt_new->shortname) { xfree(wpt_new->shortname); } @@ -106,6 +110,7 @@ interpfilt_process(void) xfree(wpt_new->description); } wpt_new->shortname = wpt_new->description = NULL; +#endif linepart(lat1, lon1, wpt->latitude, wpt->longitude, (double)(timen-time1)/ @@ -132,6 +137,10 @@ interpfilt_process(void) waypoint* wpt_new = waypt_dupe(wpt); wpt_new->SetCreationTime(distn/curdist* (wpt->creation_time.toTime_t() - time1) + time1); +#if NEW_STRINGS + wpt_new->shortname = QString(); + wpt_new->description = QString(); +#else if (wpt_new->shortname) { xfree(wpt_new->shortname); } @@ -139,6 +148,7 @@ interpfilt_process(void) xfree(wpt_new->description); } wpt_new->shortname = wpt_new->description = NULL; +#endif linepart(lat1, lon1, wpt->latitude, wpt->longitude, distn/curdist, diff --git a/gpsbabel/kml.cc b/gpsbabel/kml.cc index fd52b5606..b5267b692 100644 --- a/gpsbabel/kml.cc +++ b/gpsbabel/kml.cc @@ -286,13 +286,26 @@ void wpt_e(xg_string args, const QXmlStreamAttributes* unused) wpt_tmp_queued = 0; } +#if NEW_STRINGS +void wpt_name(xg_string args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->shortname = args; +} +#else void wpt_name(xg_string args, const QXmlStreamAttributes* unused) { if (args) { wpt_tmp->shortname = xstrdup(args); } } +#endif +#if NEW_STRINGS +void wpt_desc(const QString& args, const QXmlStreamAttributes* unused) +{ + wpt_tmp->description += args.trimmed(); +} +#else void wpt_desc(xg_string args, const QXmlStreamAttributes* unused) { if (args) { @@ -306,18 +319,22 @@ void wpt_desc(xg_string args, const QXmlStreamAttributes* unused) xfree(tmp); } } +#endif void wpt_time(xg_string args, const QXmlStreamAttributes* unused) { wpt_tmp->SetCreationTime(xml_parse_time(args)); } - +#if NEW_STRINGS +void wpt_coord(const QString& args, const QXmlStreamAttributes* attrv) +#else void wpt_coord(xg_string args, const QXmlStreamAttributes* attrv) +#endif { int n = 0; double lat, lon, alt; // Alt is actually optional. - n = sscanf(args, "%lf,%lf,%lf", &lon, &lat, &alt); + n = sscanf(CSTRc(args), "%lf,%lf,%lf", &lon, &lat, &alt); if (n >= 2) { wpt_tmp->latitude = lat; wpt_tmp->longitude = lon; @@ -343,12 +360,20 @@ void trk_coord(xg_string args, const QXmlStreamAttributes* attrv) int n = 0; route_head* trk_head = route_head_alloc(); +#if NEW_STRINGS + QString iargs = args; + if (!wpt_tmp->shortname.isEmpty()) { +#else if (wpt_tmp->shortname) { +#endif trk_head->rte_name = xstrdup(wpt_tmp->shortname); } track_add_head(trk_head); - +#if NEW_STRINGS + while ((n = sscanf(CSTR(iargs), "%lf,%lf,%lf%n", &lon, &lat, &alt, &consumed)) > 0) { +#else while ((n = sscanf(args, "%lf,%lf,%lf%n", &lon, &lat, &alt, &consumed)) > 0) { +#endif trkpt = waypt_new(); trkpt->latitude = lat; @@ -356,7 +381,7 @@ void trk_coord(xg_string args, const QXmlStreamAttributes* attrv) // Line malformed or two-arg format without alt . Rescan. if (2 == n) { - sscanf(args, "%lf,%lf%n", &lon, &lat, &consumed); + sscanf(CSTRc(args), "%lf,%lf%n", &lon, &lat, &consumed); } if (3 == n) { @@ -364,8 +389,11 @@ void trk_coord(xg_string args, const QXmlStreamAttributes* attrv) } track_add_wpt(trk_head, trkpt); - +#if NEW_STRINGS + iargs = iargs.mid(consumed); +#else args += consumed; +#endif } } @@ -644,8 +672,11 @@ void kml_output_trkdescription(const route_head* header, computed_trkdata* td) writer->writeStartElement("description"); hwriter.writeStartElement("table"); - +#if NEW_STRINGS + if (!header->rte_desc.isEmpty()) { +#else if (header->rte_desc) { +#endif kml_td(hwriter, "Description", QString(" %1 ").arg(header->rte_desc)); } kml_td(hwriter, "Distance", QString(" %1 %2 ").arg(QString::number(distance, 'f', 1)).arg(distance_units)); @@ -904,7 +935,11 @@ static void kml_output_point(const waypoint* waypointp, kml_point_type pt_type) if (export_points) { writer->writeStartElement("Placemark"); if (atoi(opt_labels)) { +#if NEW_STRINGS + writer->writeOptionalTextElement("name", waypointp->shortname); +#else writer->writeOptionalTextElement("name", QString::fromUtf8(waypointp->shortname)); +#endif } writer->writeEmptyElement("snippet"); kml_output_description(waypointp); @@ -1444,8 +1479,12 @@ static void kml_geocache_pr(const waypoint* waypointp) writer->writeEndElement(); // Close Style tag writer->writeStartElement("ExtendedData"); - +#if NEW_STRINGS + if (!waypointp->shortname.isEmpty()) { +#else if (waypointp->shortname) { +#endif + kml_write_data_element("gc_num", waypointp->shortname); } @@ -1538,7 +1577,11 @@ static void kml_waypt_pr(const waypoint* waypointp) writer->writeTextElement("description", link.url_); } } else { +#if NEW_STRINGS + if (waypointp->shortname != waypointp->description) { +#else if (strcmp(waypointp->shortname, waypointp->description)) { +#endif writer->writeOptionalTextElement("description", waypointp->description); } } @@ -2074,7 +2117,11 @@ kml_wr_position(waypoint* wpt) } /* We want our waypoint to have a name, but not our trackpoint */ +#if NEW_STRINGS + if (wpt->shortname.isEmpty()) { +#else if (!wpt->shortname) { +#endif if (wpt->fix == fix_none) { wpt->shortname = xstrdup("ESTIMATED Position"); } else { @@ -2084,10 +2131,14 @@ kml_wr_position(waypoint* wpt) switch (wpt->fix) { case fix_none: +#if NEW_STRINGS + wpt->shortname = "ESTIMATED Position"; +#else if (wpt->shortname) { xfree(wpt->shortname); } wpt->shortname = xstrdup("ESTIMATED Position"); +#endif break; case fix_unknown: break; diff --git a/gpsbabel/lmx.cc b/gpsbabel/lmx.cc index c0953f70d..faae951cc 100644 --- a/gpsbabel/lmx.cc +++ b/gpsbabel/lmx.cc @@ -196,18 +196,17 @@ lmx_write_xml(int tag, const QString& data, int indent) static void lmx_print(const waypoint* wpt) { - const char* oname; - char* odesc; - char tbuf[100]; + QString oname; + QString odesc; /* * Desparation time, try very hard to get a good shortname */ odesc = wpt->notes; - if (!odesc) { + if (odesc.isEmpty()) { odesc = wpt->description; } - if (!odesc) { + if (odesc.isEmpty()) { odesc = wpt->shortname; } @@ -217,10 +216,14 @@ lmx_print(const waypoint* wpt) if (!binary) { gbfputc('\n', ofd); } - if (oname) { + if (!oname.isEmpty()) { lmx_write_xml(0x48, oname, 3); // name } +#if NEW_STRINGS + if (!wpt->description.isEmpty()) { +#else if (wpt->description) { +#endif lmx_write_xml(0x49, wpt->description, 3); // description } lmx_start_tag(0x4A, 3); // coordinates @@ -228,6 +231,7 @@ lmx_print(const waypoint* wpt) gbfputc('\n', ofd); } + char tbuf[100]; sprintf(tbuf, "%f", wpt->latitude); lmx_write_xml(0x4B, tbuf, 4); // latitude @@ -350,31 +354,51 @@ lmx_lm_end(xg_string args, const QXmlStreamAttributes* unused) static void lmx_lm_lat(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->latitude = args.toDouble(); +#else wpt_tmp->latitude = atof(args); +#endif } static void lmx_lm_lon(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->longitude = args.toDouble(); +#else wpt_tmp->longitude = atof(args); +#endif } static void lmx_lm_alt(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->altitude = args.toDouble(); +#else wpt_tmp->altitude = atof(args); +#endif } static void lmx_lm_name(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->shortname = args; +#else wpt_tmp->shortname = xstrdup(args); +#endif } static void lmx_lm_desc(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->description = args; +#else wpt_tmp->description = xstrdup(args); +#endif } static void diff --git a/gpsbabel/lowranceusr.cc b/gpsbabel/lowranceusr.cc index dc6900610..e13e8e7bc 100644 --- a/gpsbabel/lowranceusr.cc +++ b/gpsbabel/lowranceusr.cc @@ -679,7 +679,6 @@ lowranceusr_waypt_disp(const waypoint* wpt) { int text_len, Lat, Lon, Time, SymbolId; short int WayptType; - char* name; char* comment; int alt = METERS_TO_FEET(wpt->altitude); @@ -705,37 +704,55 @@ lowranceusr_waypt_disp(const waypoint* wpt) } /* Try and make sure we have a name */ +#if NEW_STRINGS +// this kind of thing would probably be more readable like +// name = blah. +// if name.isEmpty() +// name = planB; +// if name.isEmpty() +// name = planC; +// ... + QString name; + if ((wpt->shortname.isEmpty()) || global_opts.synthesize_shortnames) { + if (!wpt->description.isEmpty() && global_opts.synthesize_shortnames) { + name = mkshort_from_wpt(mkshort_handle, wpt); + } else if (!wpt->shortname.isEmpty()) { + name = wpt->shortname; + } else if (!wpt->description.isEmpty()) { + name = wpt->description; +#else if ((! wpt->shortname) || global_opts.synthesize_shortnames) { if (wpt->description && global_opts.synthesize_shortnames) { name = mkshort_from_wpt(mkshort_handle, wpt); } else if (wpt->shortname) { - name = xstrdup(wpt->shortname); + name = wpt->shortname; } else if (wpt->description) { - name = xstrdup(wpt->description); - } else { - name = xstrdup(""); + name = wpt->description; +#endif } } else { - name = xstrdup(wpt->shortname); + name = wpt->shortname; } - text_len = strlen(name); + text_len = name.length(); if (text_len > MAXUSRSTRINGSIZE) { text_len = MAXUSRSTRINGSIZE; } gbfputint32(text_len, file_out); - gbfwrite(name, 1, text_len, file_out); + gbfwrite(CSTR(name), 1, text_len, file_out); if (global_opts.debug_level >= 1) { - printf(MYNAME " waypt_disp: Waypt name = %s\n",name); + printf(MYNAME " waypt_disp: Waypt name = %s\n", CSTR(name)); } - xfree(name); - /** * Comments are now used by the iFinder (Expedition C supports them) */ +#if NEW_STRINGS + if (wpt->description != wpt->shortname) { +#else if (wpt->description && strcmp(wpt->description, wpt->shortname) != 0) { +#endif comment = xstrdup(wpt->description); text_len = strlen(comment); if (text_len > MAXUSRSTRINGSIZE) { @@ -844,10 +861,18 @@ lowranceusr_track_hdr(const route_head* trk) char visible=1; ++trail_count; +#if NEW_STRINGS +// This whole function needs to be replaced... + if (!trk->rte_name.isEmpty()) { + name = xstrdup(trk->rte_name); + } else if (!trk->rte_desc.isEmpty()) { + name = xstrdup(trk->rte_desc); +#else if (trk->rte_name) { name = xstrdup(trk->rte_name); } else if (trk->rte_desc) { name = xstrdup(trk->rte_desc); +#endif } else { tmp_name[0]='\0'; snprintf(tmp_name, sizeof(tmp_name), "Babel %d", trail_count); @@ -897,10 +922,18 @@ lowranceusr_route_hdr(const route_head* rte) char route_reversed=0; /* route name */ +#if NEW_STRINGS +// This whole function needs to be replaced... + if (!rte->rte_name.isEmpty()) { + name = xstrdup(rte->rte_name); + } else if (!rte->rte_desc.isEmpty()) { + name = xstrdup(rte->rte_desc); +#else if (rte->rte_name) { name = xstrdup(rte->rte_name); } else if (rte->rte_desc) { name = xstrdup(rte->rte_desc); +#endif } else { tmp_name[0]='\0'; snprintf(tmp_name, sizeof(tmp_name), "Babel R%d", ++lowrance_route_count); @@ -954,10 +987,17 @@ lowranceusr_merge_track_hdr(const route_head* trk) char* name, tmp_name[20]; if (++trail_count == 1) { +#if NEW_STRINGS + if (!trk->rte_name.isEmpty()) { + name = xstrdup(trk->rte_name); + } else if (!trk->rte_desc.isEmpty()) { + name = xstrdup(trk->rte_desc); +#else if (trk->rte_name) { name = xstrdup(trk->rte_name); } else if (trk->rte_desc) { name = xstrdup(trk->rte_desc); +#endif } else { tmp_name[0]='\0'; snprintf(tmp_name, sizeof(tmp_name), "Babel %d", trail_count); diff --git a/gpsbabel/maggeo.cc b/gpsbabel/maggeo.cc index 1089d1653..e59460c3e 100644 --- a/gpsbabel/maggeo.cc +++ b/gpsbabel/maggeo.cc @@ -241,14 +241,11 @@ maggeo_waypt_pr(const waypoint* waypointp) double ilon, ilat; double lon, lat; int lon_deg, lat_deg; - char* shortname; - char* cname = NULL; const char* ctype = NULL; QString placer; ilat = waypointp->latitude; ilon = waypointp->longitude; - shortname = waypointp->shortname; lon = fabs(ilon); lat = fabs(ilat); @@ -273,8 +270,12 @@ maggeo_waypt_pr(const waypoint* waypointp) } QString placeddate = maggeo_fmtdate(waypointp->creation_time); QString lfounddate = maggeo_fmtdate(waypointp->gc_data->last_found); - cname = mkshort(desc_handle, + QString cname = mkshort(desc_handle, +#if NEW_STRINGS + waypointp->notes.isEmpty() ? waypointp->description : waypointp->notes); +#else waypointp->notes ? waypointp->notes : waypointp->description); +#endif placer = waypointp->gc_data->placer; /* @@ -295,8 +296,8 @@ maggeo_waypt_pr(const waypoint* waypointp) lon, ilon < 0 ? 'W' : 'E', waypointp->altitude == unknown_alt ? 0 : waypointp->altitude); - append(obuf, shortname); - append(obuf, cname); + append(obuf, CSTRc(waypointp->shortname)); + append(obuf, CSTR(cname)); append(obuf, placer.toUtf8().data()); append(obuf, waypointp->gc_data->hint.toUtf8().data()); append(obuf, ctype); @@ -317,10 +318,6 @@ maggeo_waypt_pr(const waypoint* waypointp) strcat(obuf, ","); } - if (cname) { - xfree(cname); - } - maggeo_writemsg(obuf); } diff --git a/gpsbabel/magproto.cc b/gpsbabel/magproto.cc index 341501189..a501c0ddc 100644 --- a/gpsbabel/magproto.cc +++ b/gpsbabel/magproto.cc @@ -519,18 +519,27 @@ retry: /* These tracks don't have names, so derive one * from input filename. */ - char* e; - const char* s = get_filename(curfname); trk_head = route_head_alloc(); /* Whack trailing extension if present. */ +#if NEW_STRINGS + QString s = get_filename(curfname); + int idx = s.indexOf('.'); + if (idx > 0) { + s.truncate(idx); + } + + trk_head->rte_name = s; +#else + char* e; + const char* s = get_filename(curfname); trk_head->rte_name = xstrdup(s); e = strrchr(trk_head->rte_name, '.'); if (e) { *e = '\0'; } - +#endif track_add_head(trk_head); } @@ -1148,7 +1157,11 @@ mag_rteparse(char* rtemsg) */ QUEUE_FOR_EACH(&rte_wpt_tmp, welem, wtmp) { waypt = (waypoint*)welem; +#if NEW_STRINGS + if (waypt->shortname == re->wpt_name) { +#else if (strcmp(waypt->shortname, re->wpt_name) == 0) { +#endif waypoint* wpt = waypt_dupe(waypt); route_add_wpt(rte_head, wpt); break; @@ -1357,8 +1370,6 @@ mag_waypt_pr(const waypoint* waypointp) char obuf[200]; char ofmtdesc[200]; QString icon_token; - char* owpt; - char* odesc; ilat = waypointp->latitude; ilon = waypointp->longitude; @@ -1384,20 +1395,26 @@ mag_waypt_pr(const waypoint* waypointp) if (get_cache_icon(waypointp)) { icon_token = mag_find_token_from_descr(get_cache_icon(waypointp)); } - +#if NEW_STRINGS + QString isrc = waypointp->notes.isEmpty() ? waypointp->description : waypointp->notes; + QString owpt = global_opts.synthesize_shortnames ? + mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname; + QString odesc = isrc; +#else String isrc = waypointp->notes ? waypointp->notes : waypointp->description; - owpt = global_opts.synthesize_shortnames ? + char* owpt = global_opts.synthesize_shortnames ? mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname; - odesc = isrc ? isrc : (char*)""; - owpt = mag_cleanse(owpt); + char* odesc = isrc ? isrc : (char*)""; +#endif + owpt = mag_cleanse(CSTRc(owpt)); if (global_opts.smart_icons && waypointp->gc_data->diff && waypointp->gc_data->terr) { sprintf(ofmtdesc, "%d/%d %s", waypointp->gc_data->diff, - waypointp->gc_data->terr, odesc); + waypointp->gc_data->terr, CSTRc(odesc)); odesc = mag_cleanse(ofmtdesc); } else { - odesc = mag_cleanse(odesc); + odesc = mag_cleanse(CSTRc(odesc)); } /* @@ -1405,7 +1422,11 @@ mag_waypt_pr(const waypoint* waypointp) * to deliver turn-by-turn popups for street routing) allow a * cap on the comments delivered so we leave space for it to route. */ +#if NEW_STRINGS + if (!odesc.isEmpty() && (wptcmtcnt++ >= wptcmtcnt_max)) { +#else if (odesc && /* !is_file && */ (wptcmtcnt++ >= wptcmtcnt_max)) { +#endif odesc[0] = 0; } @@ -1415,12 +1436,15 @@ mag_waypt_pr(const waypoint* waypointp) waypointp->altitude == unknown_alt ? 0 : waypointp->altitude, wpt_len, - owpt, - odesc, + CSTRc(owpt), + CSTRc(odesc), icon_token.toUtf8().data()); mag_writemsg(obuf); +#if NEW_STRINGS +#else xfree(owpt); xfree(odesc); +#endif if (!is_file) { if (mag_error) { @@ -1542,7 +1566,10 @@ mag_route_trl(const route_head* rte) } else { pbuff = buff2; } - +#if NEW_STRINGS +// TODO: figure out what this code is trying to do. + sprintf(pbuff, "%s,%s", CSTR(waypointp->shortname), icon_token.toUtf8().data()); +#else owpt = waypointp->shortname; if (strlen(owpt) > sizeof(buff1) - 3) { owpt[sizeof(buff1) - 3] = 0; @@ -1552,6 +1579,7 @@ mag_route_trl(const route_head* rte) sprintf(pbuff, "%s,%s", owpt, icon_token.toUtf8().data()); xfree(owpt); +#endif if ((tmp == &rte->waypoint_list) || ((i % 2) == 0)) { char expbuf[1024]; @@ -1559,8 +1587,13 @@ mag_route_trl(const route_head* rte) expbuf[0] = 0; if (explorist) { snprintf(expbuf, sizeof(expbuf), "%s,", +#if NEW_STRINGS + CSTRc(rte->rte_name)); +#else rte->rte_name ? CSTRc(rte->rte_name) : ""); +#endif } + sprintf(obuff, "PMGNRTE,%d,%d,c,%d,%s%s,%s", numlines, thisline, rte->rte_num ? rte->rte_num : route_out_count, diff --git a/gpsbabel/mapsend.cc b/gpsbabel/mapsend.cc index 97868825d..7a6f842a6 100644 --- a/gpsbabel/mapsend.cc +++ b/gpsbabel/mapsend.cc @@ -275,10 +275,10 @@ mapsend_waypt_pr(const waypoint* waypointp) unsigned int c = 0; double falt; static int cnt = 0; - const char* sn = global_opts.synthesize_shortnames ? + QString sn = global_opts.synthesize_shortnames ? mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname; - char* tmp; + QString tmp; /* * The format spec doesn't call out the character set of waypoint @@ -298,10 +298,15 @@ mapsend_waypt_pr(const waypoint* waypointp) tmp = mkshort(wpt_handle, sn); gbfputpstr(tmp, mapsend_file_out); - if (tmp) { - xfree(tmp); - } +#if NEW_STRINGS + c = waypointp->description.length(); + if (c > 30) { + c = 30; + } + gbfputc(c, mapsend_file_out); + gbfwrite(CSTR(waypointp->description), 1, c, mapsend_file_out); +#else tmp = waypointp->description; if (tmp) { c = strlen(tmp); @@ -314,6 +319,7 @@ mapsend_waypt_pr(const waypoint* waypointp) } gbfputc(c, mapsend_file_out); gbfwrite(tmp, 1, c, mapsend_file_out); +#endif /* #, icon, status */ gbfputint32(++cnt, mapsend_file_out); @@ -388,9 +394,13 @@ mapsend_route_disp(const waypoint* waypointp) route_wp_count++; /* waypoint name */ +#if NEW_STRINGS + c = waypointp->shortname.length(); +#else c = waypointp->shortname ? strlen(waypointp->shortname) : 0; +#endif gbfwrite(&c, 1, 1, mapsend_file_out); - gbfwrite(waypointp->shortname, 1, c, mapsend_file_out); + gbfwrite(CSTRc(waypointp->shortname), 1, c, mapsend_file_out); /* waypoint number */ gbfputint32(route_wp_count, mapsend_file_out); @@ -419,7 +429,6 @@ void mapsend_track_hdr(const route_head* trk) */ const char* verstring = "30"; queue* elem, *tmp; - char* tname; int i; mapsend_hdr hdr = {13, {'4','D','5','3','3','3','3','4',' ','M','S'}, {'3','0'}, ms_type_track, {0, 0, 0} @@ -449,8 +458,12 @@ void mapsend_track_hdr(const route_head* trk) hdr.ms_version[1] = verstring[1]; gbfwrite(&hdr, sizeof(hdr), 1, mapsend_file_out); - +#if NEW_STRINGS + QString tname = trk->rte_name.isEmpty() ? "Track" : trk->rte_name; + gbfputpstr(tname, mapsend_file_out); +#else /* track name */ + char* tname; if (!trk->rte_name) { tname = xstrdup("Track"); } else { @@ -459,6 +472,7 @@ void mapsend_track_hdr(const route_head* trk) gbfputpstr(tname, mapsend_file_out); xfree(tname); +#endif /* total nodes (waypoints) this track */ i = 0; diff --git a/gpsbabel/mapsource.cc b/gpsbabel/mapsource.cc index 5c11dfdda..27bb9fc46 100644 --- a/gpsbabel/mapsource.cc +++ b/gpsbabel/mapsource.cc @@ -135,14 +135,14 @@ mps_wpt_q_deinit(queue* whichQueue) * */ waypoint* -mps_find_wpt_q_by_name(const queue* whichQueue, const char* name) +mps_find_wpt_q_by_name(const queue* whichQueue, const QString& name) { queue* elem, *tmp; waypoint* waypointp; QUEUE_FOR_EACH(whichQueue, elem, tmp) { waypointp = (waypoint*) elem; - if (0 == strcmp(waypointp->shortname, name)) { + if (waypointp->shortname == name) { return waypointp; } } @@ -619,8 +619,6 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const waypoint* wpt, const int isR int reclen; int lat, lon; int icon; - const char* src = ""; /* default to empty string */ - char* ident; char* ascii_description; char zbuf[25]; char ffbuf[25]; @@ -636,16 +634,25 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const waypoint* wpt, const int isR if (WAYPT_HAS(wpt, depth) && mpsusedepth) { mps_depth = wpt->depth; } - + QString src; +#if NEW_STRINGS + if (!wpt->description.isEmpty()) { + src = wpt->description; + } + if (!wpt->notes.isEmpty()) { + src = wpt->notes; + } +#else if (wpt->description) { src = wpt->description; } if (wpt->notes) { src = wpt->notes; } - ident = global_opts.synthesize_shortnames ? +#endif + QString ident = global_opts.synthesize_shortnames ? mkshort(mkshort_handle, src) : - wpt->shortname; + CSTRc(wpt->shortname); memset(zbuf, 0, sizeof(zbuf)); memset(ffbuf, 0xff, sizeof(ffbuf)); @@ -659,8 +666,12 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const waypoint* wpt, const int isR icon = mps_converted_icon_number(icon, mps_ver, MAPSOURCE); /* two NULL (0x0) bytes at end of each string */ +#if NEW_STRINGS + ascii_description = xstrdup(wpt->description); +#else ascii_description = wpt->description ? xstrdup(wpt->description) : xstrdup(""); - reclen = strlen(ident) + strlen(ascii_description) + 2; +#endif + reclen = ident.length() + strlen(ascii_description) + 2; if ((mps_ver == 4) || (mps_ver == 5)) { /* v4.06 & V5.0*/ reclen += 85; /* "W" (1) + strlen(name) + NULL (1) + class(4) + country(sz) + @@ -668,8 +679,12 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const waypoint* wpt, const int isR + NULL (1) + prox(9) + display(4) + colour(4) + symbol(4) + city(sz) + state(sz) + facility(sz) + unknown2(1) + depth(9) + unknown3(7) */ /* -1 as reclen is interpreted from zero meaning a reclength of one */ +#if NEW_STRINGS + if (!wpt->notes.isEmpty()) { +#else if (wpt->notes) { - reclen += strlen(wpt->notes); +#endif + reclen += strlen(CSTRc(wpt->notes)); } } else { /* v3.02 */ @@ -716,7 +731,11 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const waypoint* wpt, const int isR gbfputc(1, mps_file); gbfputdbl(mps_altitude, mps_file); } +#if NEW_STRINGS + if (!wpt->description.isEmpty()) { +#else if (wpt->description) { +#endif gbfputs(ascii_description, mps_file); } gbfwrite(zbuf, 1, 1, mps_file); /* NULL termination */ @@ -748,7 +767,11 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const waypoint* wpt, const int isR gbfwrite(zbuf, 2, 1, mps_file); /* unknown */ if ((mps_ver == 4) || (mps_ver == 5)) { gbfwrite(zbuf, 4, 1, mps_file); /* unknown */ +#if NEW_STRINGS + if (!wpt->notes.isEmpty()) { +#else if (wpt->notes) { +#endif gbfputs(wpt->notes, mps_file); } gbfwrite(zbuf, 1, 1, mps_file); /* string termination */ @@ -767,10 +790,10 @@ mps_waypoint_w_unique_wrapper(const waypoint* wpt) waypoint* wptfound = NULL; /* Search for this waypoint in the ones already written */ - wptfound = mps_find_wpt_q_by_name(&written_wpt_head, wpt->shortname); + wptfound = mps_find_wpt_q_by_name(&written_wpt_head, CSTRc(wpt->shortname)); /* is the next line necessary? Assumes we know who's called us and in what order */ if (wptfound == NULL) { - wptfound = mps_find_wpt_q_by_name(&written_route_wpt_head, wpt->shortname); + wptfound = mps_find_wpt_q_by_name(&written_route_wpt_head, CSTRc(wpt->shortname)); } /* if this waypoint hasn't been written then it is okay to do so */ @@ -797,11 +820,11 @@ mps_route_wpt_w_unique_wrapper(const waypoint* wpt) waypoint* wptfound = NULL; /* Search for this waypoint in the ones already written */ - wptfound = mps_find_wpt_q_by_name(&written_wpt_head, wpt->shortname); + wptfound = mps_find_wpt_q_by_name(&written_wpt_head, CSTRc(wpt->shortname)); if (wptfound == NULL) /* so, not a real wpt, so must check route wpts already written as reals */ { - wptfound = mps_find_wpt_q_by_name(&written_route_wpt_head, wpt->shortname); + wptfound = mps_find_wpt_q_by_name(&written_route_wpt_head, CSTRc(wpt->shortname)); } /* if this waypoint hasn't been written then it is okay to do so @@ -1127,8 +1150,6 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) char* rname; char hdr[20]; char zbuf[20]; - const char* src = ""; - char* ident; waypoint* testwpt; time_t uniqueValue = 0; @@ -1183,16 +1204,25 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) } } + QString src; +#if NEW_STRINGS + if (!testwpt->description.isEmpty()) { +#else if (testwpt->description) { +#endif src = testwpt->description; } +#if NEW_STRINGS + if (!testwpt->notes.isEmpty()) { +#else if (testwpt->notes) { +#endif src = testwpt->notes; } - ident = global_opts.synthesize_shortnames ? + QString ident = global_opts.synthesize_shortnames ? mkshort(mkshort_handle, src) : - testwpt->shortname; - allWptNameLengths += strlen(ident) + 1; + CSTRc(testwpt->shortname); + allWptNameLengths += ident.length() + 1; rte_datapoints++; } @@ -1202,7 +1232,11 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) } /* route name */ +#if NEW_STRINGS + if (rte->rte_name.isEmpty()) { +#else if (!rte->rte_name) { +#endif sprintf(hdr, "Route%04x", (unsigned) uniqueValue); rname = xstrdup(hdr); } else { @@ -1291,8 +1325,6 @@ mps_routedatapoint_w(gbfile* mps_file, int mps_ver, const waypoint* rtewpt) int lon; char zbuf[20]; char ffbuf[20]; - const char* src = ""; - char* ident; int reclen; int maxlat; @@ -1402,15 +1434,25 @@ mps_routedatapoint_w(gbfile* mps_file, int mps_ver, const waypoint* rtewpt) } + QString src; +#if NEW_STRINGS + if (!rtewpt->description.isEmpty()) { + src = rtewpt->description; + } + if (!rtewpt->notes.isEmpty()) { + src = rtewpt->notes; + } +#else if (rtewpt->description) { src = rtewpt->description; } if (rtewpt->notes) { src = rtewpt->notes; } - ident = global_opts.synthesize_shortnames ? +#endif + QString ident = global_opts.synthesize_shortnames ? mkshort(mkshort_handle, src) : - rtewpt->shortname; + CSTRc(rtewpt->shortname); gbfputs(ident, mps_file); gbfwrite(zbuf, 1, 1, mps_file); /* NULL termination to ident */ @@ -1606,7 +1648,11 @@ mps_trackhdr_w(gbfile* mps_file, int mps_ver, const route_head* trk) } /* track name */ +#if NEW_STRINGS + if (trk->rte_name.isEmpty()) { +#else if (!trk->rte_name) { +#endif sprintf(hdr, "Track%04x", (unsigned) uniqueValue); tname = xstrdup(hdr); } else { diff --git a/gpsbabel/mkshort.cc b/gpsbabel/mkshort.cc index 7bd919e8b..167c1de63 100644 --- a/gpsbabel/mkshort.cc +++ b/gpsbabel/mkshort.cc @@ -585,7 +585,7 @@ mkshort(short_handle h, const QString& istring) * As above, but arg list is a waypoint so we can centralize * the code that considers the alternate sources. */ -char* +String mkshort_from_wpt(short_handle h, const waypoint* wpt) { /* This probably came from a Groundspeak Pocket Query @@ -594,15 +594,27 @@ mkshort_from_wpt(short_handle h, const waypoint* wpt) * more stuff than should be in any one field... */ if (wpt->gc_data->diff && wpt->gc_data->terr && +#if NEW_STRINGS + !wpt->notes.isEmpty()) { +#else wpt->notes && wpt->notes[0]) { +#endif return mkshort(h, wpt->notes); } +#if NEW_STRINGS + if (!wpt->description.isEmpty()) { +#else if (wpt->description) { +#endif return mkshort(h, wpt->description); } +#if NEW_STRINGS + if (!wpt->notes.isEmpty()) { +#else if (wpt->notes) { +#endif return mkshort(h, wpt->notes); } diff --git a/gpsbabel/mmo.cc b/gpsbabel/mmo.cc index 3522ac011..c0edb8131 100644 --- a/gpsbabel/mmo.cc +++ b/gpsbabel/mmo.cc @@ -461,8 +461,11 @@ mmo_read_CObjWaypoint(mmo_data_t* data) data->name, data->visible ? "yes" : "NO", data->objid)); data->data = wpt = waypt_new(); +#if NEW_STRINGS + wpt->shortname = QString::fromLatin1(data->name); +#else wpt->shortname = xstrdup(data->name); - +#endif time = data->mtime; if (! time) { time = data->ctime; @@ -521,7 +524,11 @@ mmo_read_CObjWaypoint(mmo_data_t* data) } if (*cend++) { +#if NEW_STRINGS + wpt->notes = QString::fromLatin1(cend); +#else wpt->notes = xstrdup(cend); +#endif } if (wpt->HasUrlLink()) { @@ -531,9 +538,12 @@ mmo_read_CObjWaypoint(mmo_data_t* data) wpt->notes = xstrdup(str); } xfree(str); - +#if NEW_STRINGS + if (!wpt->notes.isEmpty()) { +#else if (wpt->notes) { - DBG((sobj, "notes = \"%s\"\n", wpt->notes)); +#endif + DBG((sobj, "notes = \"%s\"\n", CSTRc(wpt->notes))); } mmo_fillbuf(buf, 12, 1); @@ -980,15 +990,20 @@ mmo_finalize_rtept_cb(const waypoint* wptref) wpt->latitude = wpt2->latitude; wpt->longitude = wpt2->longitude; +#if NEW_STRINGS + wpt->shortname = wpt2->shortname; + wpt->description = wpt2->description; + wpt->notes = wpt2->notes; +#else xfree(wpt->shortname); wpt->shortname = xstrdup(wpt2->shortname); - if (wpt2->description) { wpt->description = xstrdup(wpt2->description); } if (wpt2->notes) { wpt->notes = xstrdup(wpt2->notes); } +#endif if (wpt2->HasUrlLink()) { UrlLink l = wpt2->GetUrlLink(); wpt->notes = xstrdup(l.url_.toUtf8().data()); @@ -1237,7 +1252,7 @@ mmo_write_obj_head(const char* sobj, const char* name, const time_t ctime, static void mmo_write_wpt_cb(const waypoint* wpt) { - char* str, *cx; + char* str; int objid; time_t time; int icon = 0; @@ -1265,7 +1280,11 @@ mmo_write_wpt_cb(const waypoint* wpt) DBG(("write", "waypoint \"%s\"\n", wpt->shortname ? wpt->shortname : "Mark")); objid = mmo_write_obj_head("CObjWaypoint", +#if NEW_STRINGS + wpt->shortname.isEmpty() ? "Mark" : CSTRc(wpt->shortname), time, obj_type_wpt); +#else (wpt->shortname && *wpt->shortname) ? CSTRc(wpt->shortname) : "Mark", time, obj_type_wpt); +#endif data = mmo_register_object(objid, wpt, wptdata); data->refct = 1; mmo_write_category("CCategory", (mmo_datatype == rtedata) ? "Waypoints" : "Marks"); @@ -1290,7 +1309,7 @@ mmo_write_wpt_cb(const waypoint* wpt) str = xstrdup(""); } - cx = wpt->notes; + QString cx = wpt->notes; if (cx == NULL) { cx = wpt->description; } @@ -1304,7 +1323,7 @@ mmo_write_wpt_cb(const waypoint* wpt) tmp.is_html = 1; cx = kml = strip_html(&tmp); } - str = xstrappend(str, cx); + str = xstrappend(str, CSTR(cx)); if (kml) { xfree(kml); } @@ -1362,7 +1381,11 @@ mmo_write_rte_head_cb(const route_head* rte) } objid = mmo_write_obj_head("CObjRoute", +#if NEW_STRINGS + rte->rte_name.isEmpty() ? "Route" : CSTRc(rte->rte_name), time, obj_type_rte); +#else (rte->rte_name && *rte->rte_name) ? CSTRc(rte->rte_name) : "Route", time, obj_type_rte); +#endif mmo_register_object(objid, rte, rtedata); mmo_write_category("CCategory", "Route"); gbfputc(0, fout); /* unknown */ @@ -1413,7 +1436,11 @@ mmo_write_trk_head_cb(const route_head* trk) } objid = mmo_write_obj_head("CObjTrack", +#if NEW_STRINGS + trk->rte_name.isEmpty() ? "Track" : CSTRc(trk->rte_name), gpsbabel_time, obj_type_trk); +#else (trk->rte_name && *trk->rte_name) ? CSTRc(trk->rte_name) : "Track", gpsbabel_time, obj_type_trk); +#endif mmo_write_category("CCategory", "Track"); gbfputuint16(trk->rte_waypt_ct, fout); @@ -1518,7 +1545,6 @@ mmo_write(void) track_disp_all(mmo_write_trk_head_cb, mmo_write_trk_tail_cb, mmo_write_wpt_cb); } -/**************************************************************************/ ff_vecs_t mmo_vecs = { ff_type_file, @@ -1534,5 +1560,3 @@ ff_vecs_t mmo_vecs = { CET_CHARSET_MS_ANSI, 0 }; - -/**************************************************************************/ diff --git a/gpsbabel/naviguide.cc b/gpsbabel/naviguide.cc index 540ff9399..c47e0a318 100644 --- a/gpsbabel/naviguide.cc +++ b/gpsbabel/naviguide.cc @@ -25,6 +25,8 @@ #include "jeeps/gpsmath.h" #include #include +#include +#include #define MYNAME "Naviguide" @@ -369,18 +371,19 @@ ng_read_file_header(void) static void data_read(void) { - int n; - unsigned i; - waypoint* wpt_tmp; - if (process_rte) { rte_head = route_head_alloc(); route_add_head(rte_head); } - for (n = 0; n < nof_wp; ++n) { + QTextCodec* codec = QTextCodec::codecForName("Hebrew"); + if (!codec) { + fatal(MYNAME ": Unable to locate codec for Hebrew"); + } + + for (int n = 0; n < nof_wp; ++n) { - wpt_tmp = waypt_new(); + waypoint* wpt_tmp = waypt_new(); /* Read waypoint data */ @@ -397,7 +400,7 @@ data_read(void) } /* Clear commas form the comment for CSV file commonality */ - for (i = 0; i shortname = codec->toUnicode(WPNC.strName); + wpt_tmp->description = codec->toUnicode(strComment); +#else wpt_tmp->shortname = xstrdup(WPNC.strName); wpt_tmp->description = xstrdup(strComment); +#endif if (process_rte) { route_add_wpt(rte_head, wpt_tmp); diff --git a/gpsbabel/navilink.cc b/gpsbabel/navilink.cc index 9bf353420..63e883a46 100644 --- a/gpsbabel/navilink.cc +++ b/gpsbabel/navilink.cc @@ -207,7 +207,11 @@ compare_waypoints(const waypoint* waypt1, const waypoint* waypt2) return waypt1->latitude == waypt2->latitude && waypt1->longitude == waypt2->longitude && waypt1->altitude == waypt2->altitude && +#if NEW_STRINGS + waypt1->shortname == waypt2->shortname; +#else strcmp(waypt1->shortname, waypt2->shortname) == 0; +#endif } unsigned @@ -426,7 +430,7 @@ encode_waypoint(const waypoint* waypt, unsigned char* buffer) buffer[0] = 0x00; buffer[1] = 0x40; le_write16(buffer + 2, 0); - strncpy((char*)buffer + 4, waypt->shortname, 6); + strncpy((char*)buffer + 4, CSTRc(waypt->shortname), 6); buffer[10] = 0; buffer[11] = 0; encode_position(waypt, buffer + 12); @@ -739,10 +743,10 @@ static void serial_write_route_end(const route_head* route) { unsigned char* data; - unsigned src; - unsigned sr; + unsigned src; + unsigned sr; unsigned char id[1]; - const char* rte_name; + QString rte_name; rte_name = route->rte_name; if (rte_name == NULL) { @@ -759,7 +763,7 @@ serial_write_route_end(const route_head* route) data[2] = 0; data[3] = 0x20; memset(data + 4, 0, 14); - strncpy((char*)data + 4, rte_name, 13); + strncpy((char*)data + 4, CSTR(rte_name), 13); data[18] = 0; data[19] = 0; le_write32(data + 20, 0); diff --git a/gpsbabel/netstumbler.cc b/gpsbabel/netstumbler.cc index a417a1b14..577b32815 100644 --- a/gpsbabel/netstumbler.cc +++ b/gpsbabel/netstumbler.cc @@ -276,8 +276,11 @@ compare(const void* a, const void* b) waypoint* wpt_a = ((const htable_t*)a)->wpt; waypoint* wpt_b = ((const htable_t*)b)->wpt; - +#if NEW_STRINGS + return wpt_a->description.compare(wpt_b->description); +#else return strcmp(wpt_a->description, wpt_b->description); +#endif } } @@ -292,8 +295,6 @@ fix_netstumbler_dupes(void) { int i, ct = waypt_count(), serial = 0; htable_t* htable, *bh; - const char* snptr; - char* tmp_sn; unsigned long last_crc; char ssid[32 + 5 + 1]; @@ -313,10 +314,9 @@ fix_netstumbler_dupes(void) QUEUE_FOR_EACH(&waypt_head, elem, tmp) { bh->wpt = (waypoint*) elem; #endif - snptr = bh->wpt->shortname; - tmp_sn = strlower(xstrdup(snptr)); - bh->crc = get_crc32(tmp_sn, strlen(snptr)); - xfree(tmp_sn); + QString snptr = bh->wpt->shortname; + QString tmp_sn = snptr.toLower(); + bh->crc = get_crc32(CSTR(tmp_sn), tmp_sn.length()); i ++; bh ++; } @@ -327,9 +327,13 @@ fix_netstumbler_dupes(void) for (i = 0, bh = htable; i < ct; i++, bh++) { if (last_crc == bh->crc) { +#if NEW_STRINGS + bh->wpt->shortname += QString("/%1").arg(++serial); +#else snprintf(ssid, sizeof ssid, "%s/%d", CSTRc(bh->wpt->shortname), ++serial); xfree(bh->wpt->shortname); bh->wpt->shortname = xstrdup(ssid); +#endif } else { last_crc = bh->crc; } diff --git a/gpsbabel/nmea.cc b/gpsbabel/nmea.cc index 390039f69..abc07da0e 100644 --- a/gpsbabel/nmea.cc +++ b/gpsbabel/nmea.cc @@ -287,10 +287,14 @@ nmea_rd_init(const char* fname) if (!wpt) { return; } +#if NEW_STRINGS + wpt->shortname = "Position"; +#else if (wpt->shortname) { xfree(wpt->shortname); } wpt->shortname = xstrdup("Position"); +#endif nmea_add_wpt(wpt, NULL); return; } @@ -1210,7 +1214,7 @@ nmea_wayptpr(const waypoint* wpt) { char obuf[200]; double lat,lon; - char* s; + String s; int cksum; lat = degrees2ddmm(wpt->latitude); @@ -1223,7 +1227,7 @@ nmea_wayptpr(const waypoint* wpt) snprintf(obuf, sizeof(obuf), "GPWPL,%08.3f,%c,%09.3f,%c,%s", fabs(lat), lat < 0 ? 'S' : 'N', - fabs(lon), lon < 0 ? 'W' : 'E', s + fabs(lon), lon < 0 ? 'W' : 'E', CSTRc(s) ); cksum = nmea_cksum(obuf); @@ -1232,8 +1236,10 @@ nmea_wayptpr(const waypoint* wpt) gbfflush(file_out); gb_sleep(sleepus); } - +#if NEW_STRINGS +#else xfree(s); +#endif } diff --git a/gpsbabel/osm.cc b/gpsbabel/osm.cc index a8f33936c..6e62a2009 100644 --- a/gpsbabel/osm.cc +++ b/gpsbabel/osm.cc @@ -532,14 +532,24 @@ osm_node_tag(xg_string args, const QXmlStreamAttributes* attrv) str = osm_strip_html(value); if (strcmp(key, "name") == 0) { +#if NEW_STRINGS + if (wpt->shortname.isEmpty()) { + wpt->shortname = str; + } +#else if (! wpt->shortname) { wpt->shortname = xstrdup(str); } +#endif } else if (strcmp(key, "name:en") == 0) { +#if NEW_STRINGS + wpt->shortname = str; +#else if (wpt->shortname) { xfree(wpt->shortname); } wpt->shortname = xstrdup(str); +#endif } else if ((ikey = osm_feature_ikey(key)) >= 0) { char* id = osm_feature_symbol(ikey, value); wpt->icon_descr = id; @@ -547,6 +557,14 @@ osm_node_tag(xg_string args, const QXmlStreamAttributes* attrv) xfree(id); } } else if (strcmp(key, "note") == 0) { +#if NEW_STRINGS + if (wpt->notes.isEmpty()) { + wpt->notes = str; + } else { + wpt->notes += "; "; + wpt->notes += str; + } +#else if (wpt->notes) { char* tmp; xasprintf(&tmp, "%s; %s", CSTRc(wpt->notes), str); @@ -555,6 +573,7 @@ osm_node_tag(xg_string args, const QXmlStreamAttributes* attrv) } else { wpt->notes = xstrdup(str); } +#endif } else if (strcmp(key, "gps:hdop") == 0) { wpt->hdop = atof(str); } else if (strcmp(key, "gps:vdop") == 0) { @@ -629,14 +648,24 @@ osm_way_tag(xg_string args, const QXmlStreamAttributes* attrv) str = osm_strip_html(value); if (strcmp(key, "name") == 0) { +#if NEW_STRINGS + if (rte->rte_name.isEmpty()) { + rte->rte_name = str; + } +#else if (! rte->rte_name) { rte->rte_name = xstrdup(str); } +#endif } else if (strcmp(key, "name:en") == 0) { +#if NEW_STRINGS + rte->rte_name = str; +#else if (rte->rte_name) { xfree(rte->rte_name); } rte->rte_name = xstrdup(str); +#endif } xfree(str); @@ -698,11 +727,11 @@ osm_init_icons(void) } static void -osm_write_tag(const char* key, const char* value) +osm_write_tag(const QString& key, const QString& value) { - if (value && *value) { - char* str = xml_entitize(value); - gbfprintf(fout, " \n", key, str); + if (!value.isEmpty()) { + char* str = xml_entitize(CSTR(value)); + gbfprintf(fout, " \n", CSTR(key), str); xfree(str); } } @@ -761,7 +790,11 @@ static QString osm_name_from_wpt(const waypoint* wpt) { QString name = QString("%1\01%2\01%3") +#if NEW_STRINGS + .arg(wpt->shortname) +#else .arg((wpt->shortname) ? CSTRc(wpt->shortname) : "") +#endif .arg(wpt->latitude) .arg(wpt->longitude); return name; @@ -835,7 +868,11 @@ osm_waypt_disp(const waypoint* wpt) } osm_write_tag("name", wpt->shortname); +#if NEW_STRINGS + osm_write_tag("note", (wpt->notes.isEmpty()) ? wpt->description : wpt->notes); +#else osm_write_tag("note", (wpt->notes) ? wpt->notes : wpt->description); +#endif if (!wpt->icon_descr.isNull()) { osm_disp_feature(wpt); } diff --git a/gpsbabel/overlay.cc b/gpsbabel/overlay.cc index 5426ff365..d285a0c5e 100644 --- a/gpsbabel/overlay.cc +++ b/gpsbabel/overlay.cc @@ -222,7 +222,11 @@ static void route_add_name(const route_head* hd) route_head* route; route = (route_head*) hd; +#if NEW_STRINGS + grp = route->rte_name.toInt(); +#else grp = atoi(route->rte_name); +#endif i = 0; while (irte_name = name; +#else route->rte_name = (char*) xrealloc(route->rte_name,(strlen(name)+1)*sizeof(char)); strcpy(route->rte_name,name); +#endif } static void ovl_read(void) @@ -527,7 +535,7 @@ static void symbol_init(const route_head* hd) govl_group_cnt++; } -static void symbol_text(double east,double north,char* text,int group) +static void symbol_text(double east,double north,const QString& text,int group) { gbfprintf(fpout,"[Symbol %d]\n",govl_symbol_cnt+1); gbfprintf(fpout,"Typ=2\n"); // Text @@ -540,7 +548,7 @@ static void symbol_text(double east,double north,char* text,int group) gbfprintf(fpout,"Dir=%d\n",100+((int) govl_dir)); gbfprintf(fpout,"XKoord=%.8lf\n",east); // precision 8 = better than 1mm gbfprintf(fpout,"YKoord=%.8lf\n",north); - gbfprintf(fpout,"Text=%s\n",text); + gbfprintf(fpout,"Text=%s\n",CSTR(text)); govl_symbol_cnt++; } @@ -631,21 +639,20 @@ static void symbol_deinit(const route_head* hd) static void overlay_waypt_pr(const waypoint* waypointp) { const char* oname; - char* odesc; /* * Desparation time, try very hard to get a good shortname */ - odesc = waypointp->notes; - if (!odesc) { + QString odesc = waypointp->notes; + if (odesc.isEmpty()) { odesc = waypointp->description; } - if (!odesc) { + if (odesc.isEmpty()) { odesc = waypointp->shortname; } oname = global_opts.synthesize_shortnames ? - mkshort(mkshort_handle, odesc) : - waypointp->shortname; + mkshort(mkshort_handle, CSTR(odesc)) : + CSTRc(waypointp->shortname); gbfprintf(fpout,"[Symbol %d]\n",govl_symbol_cnt+1); gbfprintf(fpout,"Typ=1\n"); diff --git a/gpsbabel/ozi.cc b/gpsbabel/ozi.cc index 4f4e68498..c10210c07 100644 --- a/gpsbabel/ozi.cc +++ b/gpsbabel/ozi.cc @@ -246,7 +246,11 @@ ozi_track_hdr(const route_head* rte) ozi_openfile(ozi_ofname); gbfprintf(file_out, ozi_trk_header, altunit == 'f' ? "Feet" : "Meters", +#if NEW_STRINGS + rte->rte_name.isEmpty() ? "ComplimentsOfGPSBabel" : CSTRc(rte->rte_name)); +#else rte->rte_name ? CSTRc(rte->rte_name) : "ComplimentsOfGPSBabel"); +#endif } track_out_count++; @@ -316,9 +320,13 @@ ozi_route_hdr(const route_head* rte) gbfprintf(file_out, "R,%d,%s,%s,\r\n", route_out_count, +#if NEW_STRINGS + CSTRc(rte->rte_name), + CSTRc(rte->rte_desc)); +#else rte->rte_name ? CSTRc(rte->rte_name) : "", rte->rte_desc ? CSTRc(rte->rte_desc) : ""); - +#endif } static void @@ -362,11 +370,19 @@ ozi_route_disp(const waypoint* waypointp) gbfprintf(file_out, "W,%d,,%d,%s,%.6f,%.6f,%s,0,1,3,0,65535,%s,0,0\r\n", route_out_count, route_wpt_count, +#if NEW_STRINGS + CSTR(waypointp->shortname), +#else waypointp->shortname ? CSTRc(waypointp->shortname) : "", +#endif waypointp->latitude, waypointp->longitude, ozi_time, +#if NEW_STRINGS + CSTR(waypointp->description)); +#else waypointp->description ? CSTRc(waypointp->description) : ""); +#endif } @@ -870,8 +886,13 @@ ozi_waypt_pr(const waypoint* wpt) static int index = 0; double alt; char ozi_time[16]; +#if NEW_STRINGS + QString description; + QString shortname; +#else char* description; char* shortname; +#endif int faked_fsdata = 0; ozi_fsdata* fs = NULL; int icon = 0; @@ -890,9 +911,13 @@ ozi_waypt_pr(const waypoint* wpt) } else { alt = wpt->altitude * alt_scale; } - +#if NEW_STRINGS + if ((wpt->shortname.isEmpty()) || (global_opts.synthesize_shortnames)) { + if (!wpt->description.isEmpty()) { +#else if ((!wpt->shortname) || (global_opts.synthesize_shortnames)) { if (wpt->description) { +#endif if (global_opts.synthesize_shortnames) { shortname = mkshort_from_wpt(mkshort_handle, wpt); } else { @@ -905,9 +930,13 @@ ozi_waypt_pr(const waypoint* wpt) } else { shortname = csv_stringclean(wpt->shortname, BADCHARS); } - +#if NEW_STRINGS + if (wpt->description.isEmpty()) { + if (!shortname.isEmpty()) { +#else if (!wpt->description) { if (shortname) { +#endif description = csv_stringclean(shortname, BADCHARS); } else { description = xstrdup(""); @@ -924,8 +953,8 @@ ozi_waypt_pr(const waypoint* wpt) gbfprintf(file_out, "%d,%s,%.6f,%.6f,%s,%d,%d,%d,%d,%d,%s,%d,%d,", - index, shortname, wpt->latitude, wpt->longitude, ozi_time, icon, - 1, 3, fs->fgcolor, fs->bgcolor, description, 0, 0); + index, CSTRc(shortname), wpt->latitude, wpt->longitude, ozi_time, icon, + 1, 3, fs->fgcolor, fs->bgcolor, CSTRc(description), 0, 0); if (WAYPT_HAS(wpt, proximity) && (wpt->proximity > 0)) { gbfprintf(file_out, "%.1f,", wpt->proximity * prox_scale); } else if (proximity > 0) { @@ -934,9 +963,11 @@ ozi_waypt_pr(const waypoint* wpt) gbfprintf(file_out,"%d,", 0); } gbfprintf(file_out, "%.0f,%d,%d,%d\r\n", alt, 6, 0, 17); - +#if NEW_STRINGS +#else xfree(description); xfree(shortname); +#endif if (faked_fsdata) { xfree(fs); diff --git a/gpsbabel/pcx.cc b/gpsbabel/pcx.cc index 4d39f710a..e938ac17e 100644 --- a/gpsbabel/pcx.cc +++ b/gpsbabel/pcx.cc @@ -344,7 +344,7 @@ gpsutil_disp(const waypoint* wpt) gbfprintf(file_out, "W %-6.6s %c%08.5f %c%011.5f %s %5.f %-40.40s %5e %d\n", global_opts.synthesize_shortnames ? - mkshort_from_wpt(mkshort_handle, wpt) : + CSTRc(mkshort_from_wpt(mkshort_handle, wpt)) : CSTRc(wpt->shortname), lat < 0.0 ? 'S' : 'N', fabs(lat), @@ -360,39 +360,35 @@ gpsutil_disp(const waypoint* wpt) static void pcx_track_hdr(const route_head* trk) { - char* name; char buff[20]; route_ctr++; snprintf(buff, sizeof(buff)-1, "Trk%03d", route_ctr); - name = mkshort(mkshort_handle2, (trk->rte_name != NULL) ? trk->rte_name : buff); + QString name = mkshort(mkshort_handle2, (trk->rte_name != NULL) ? trk->rte_name : buff); /* Carto Exploreur (popular in France) chokes on trackname headers, * so provide option to supppress these. */ if (!cartoexploreur) { - gbfprintf(file_out, "\n\nH TN %s\n", name); + gbfprintf(file_out, "\n\nH TN %s\n", CSTR(name)); } - xfree(name); gbfprintf(file_out, "H LATITUDE LONGITUDE DATE TIME ALT ;track\n"); } static void pcx_route_hdr(const route_head* rte) { - char* name; char buff[20]; route_ctr++; snprintf(buff, sizeof(buff)-1, "Rte%03d", route_ctr); - name = mkshort(mkshort_handle2, (rte->rte_name != NULL) ? rte->rte_name : buff); + QString name = mkshort(mkshort_handle2, (rte->rte_name != NULL) ? rte->rte_name : buff); /* see pcx_track_hdr */ if (!cartoexploreur) { - gbfprintf(file_out, "\n\nR %s\n", name); + gbfprintf(file_out, "\n\nR %s\n", CSTR(name)); } - xfree(name); gbfprintf(file_out, "\n" "H IDNT LATITUDE LONGITUDE DATE TIME ALT DESCRIPTION PROXIMITY SYMBOL ;waypts\n"); } diff --git a/gpsbabel/pocketfms_fp.cc b/gpsbabel/pocketfms_fp.cc index a90436d47..c317ff22a 100644 --- a/gpsbabel/pocketfms_fp.cc +++ b/gpsbabel/pocketfms_fp.cc @@ -70,9 +70,17 @@ rd_deinit(void) if (head != NULL) { route->rte_name = xstrdup(head->shortname); } +#if NEW_STRINGS + route->rte_name += " - "; +#else route->rte_name = xstrappend(route->rte_name, " - "); +#endif if (tail != NULL) { +#if NEW_STRINGS + route->rte_name += tail->shortname; +#else route->rte_name = xstrappend(route->rte_name, tail->shortname); +#endif tail->altitude = dest_altitude; } } @@ -116,49 +124,81 @@ void wpt_e(xg_string args, const QXmlStreamAttributes* unused) void wpt_from_lat(xg_string args, const QXmlStreamAttributes* unused) { if (wpt_from != NULL) { +#if NEW_STRINGS + wpt_from->latitude = args.toDouble(); +#else wpt_from->latitude = atof(args); +#endif } } void wpt_from_lon(xg_string args, const QXmlStreamAttributes* unused) { if (wpt_from != NULL) { +#if NEW_STRINGS + wpt_from->longitude = args.toDouble(); +#else wpt_from->longitude = atof(args); +#endif } } void wpt_from_name(xg_string args, const QXmlStreamAttributes* unused) { if (wpt_from != NULL) { +#if NEW_STRINGS + wpt_from->shortname += args; +#else wpt_from->shortname = xstrappend(wpt_from->shortname, args); +#endif } } void wpt_from_elev(xg_string args, const QXmlStreamAttributes* unused) { if (wpt_from != NULL) { +#if NEW_STRINGS + wpt_from->altitude = FEET_TO_METERS(args.toDouble()); +#else wpt_from->altitude = FEET_TO_METERS(atof(args)); +#endif } } void wpt_to_lat(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_to->latitude = args.toDouble(); +#else wpt_to->latitude = atof(args); +#endif } void wpt_to_lon(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_to->longitude = args.toDouble(); +#else wpt_to->longitude = atof(args); +#endif } void wpt_to_name(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_to->shortname += args; +#else wpt_to->shortname = xstrappend(wpt_to->shortname, args); +#endif } void wpt_to_elev(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + dest_altitude = FEET_TO_METERS(args.toDouble()); +#else dest_altitude = FEET_TO_METERS(atof(args)); +#endif } void wpt_altitude(xg_string args, const QXmlStreamAttributes* attrv) diff --git a/gpsbabel/pocketfms_wp.cc b/gpsbabel/pocketfms_wp.cc index 1ca8bed09..279115485 100644 --- a/gpsbabel/pocketfms_wp.cc +++ b/gpsbabel/pocketfms_wp.cc @@ -103,13 +103,23 @@ static void enigma_waypt_disp(const waypoint* wpt) { char* t; +#if NEW_STRINGS + if (!wpt->shortname.isEmpty()) { + // The output might have a space or control character. + int i, l = wpt->shortname.length(); +#else if (wpt->shortname) { // The output might have a space or control character. int i, l = strlen(wpt->shortname); +#endif t = (char*) xmalloc(l + 1); char* d = t; for (i = 0; i < l; i++) { +#if NEW_STRINGS + char s = wpt->shortname[i].cell(); +#else char s = wpt->shortname[i]; +#endif if (isgraph(s)) { *d++ = s; } diff --git a/gpsbabel/psitrex.cc b/gpsbabel/psitrex.cc index 261947506..f514428cf 100644 --- a/gpsbabel/psitrex.cc +++ b/gpsbabel/psitrex.cc @@ -357,7 +357,7 @@ psit_waypoint_w(gbfile* psit_file, const waypoint* wpt) ident = global_opts.synthesize_shortnames ? mkshort(mkshort_handle, src) : - wpt->shortname; + CSTRc(wpt->shortname); gbfprintf(psit_file, " %-6s, ", ident); icon = gt_find_icon_number_from_desc(wpt->icon_descr, PCX); @@ -498,12 +498,21 @@ psit_routehdr_w(gbfile* psit_file, const route_head* rte) } /* route name */ +#if NEW_STRINGS + if (rte->rte_name.isEmpty()) { + sprintf(hdr, "Route%04x", (unsigned) uniqueValue); + rname = xstrdup(hdr); + } else { + rname = xstrdup(rte->rte_name); + } +#else if (!rte->rte_name) { sprintf(hdr, "Route%04x", (unsigned) uniqueValue); rname = xstrdup(hdr); } else { rname = xstrdup(rte->rte_name); } +#endif /* check for psitrex comment sign; replace with '$' */ while ((c = strchr(rname, '#'))) { *c = '$'; @@ -658,7 +667,11 @@ psit_trackhdr_w(gbfile* psit_file, const route_head* trk) } /* track name */ +#if NEW_STRINGS + if (trk->rte_name.isEmpty()) { +#else if (!trk->rte_name) { +#endif sprintf(hdr, "Track%04x", (unsigned) uniqueValue); tname = xstrdup(hdr); } else { diff --git a/gpsbabel/raymarine.cc b/gpsbabel/raymarine.cc index 1c7d16aff..cbe6051bc 100644 --- a/gpsbabel/raymarine.cc +++ b/gpsbabel/raymarine.cc @@ -278,7 +278,11 @@ static char same_points(const waypoint* A, const waypoint* B) { return ( /* !!! We are case-sensitive !!! */ +#if NEW_STRINGS + (A->shortname == B->shortname) && +#else (strcmp(A->shortname, B->shortname) == 0) && +#endif (A->latitude == B->latitude) && (A->longitude == B->longitude)); } @@ -307,7 +311,7 @@ register_waypt(const waypoint* ref, const char is_rtept) } } - wpt->extra_data = (void*)mkshort(hshort_wpt, wpt->shortname); + wpt->extra_data = (void*)mkshort(hshort_wpt, CSTR(wpt->shortname)); waypt_table[waypt_table_ct] = (waypoint*)wpt; waypt_table_ct++; @@ -330,14 +334,17 @@ qsort_cb(const void* a, const void* b) { const waypoint* wa = *(waypoint**)a; const waypoint* wb = *(waypoint**)b; - +#if NEW_STRINGS + return wa->shortname.compare(wb->shortname); +#else return strcmp(wa->shortname, wb->shortname); +#endif } static void write_waypoint(gbfile* fout, const waypoint* wpt, const int waypt_no, const char* location) { - const char* notes; + QString notes; char* name; double time; @@ -367,7 +374,7 @@ write_waypoint(gbfile* fout, const waypoint* wpt, const int waypt_no, const char "Notes=%s" LINE_FEED, 0.0, 0.0, find_symbol_num(wpt->icon_descr), - notes + CSTR(notes) ); gbfprintf(fout, "Rel=" LINE_FEED "RelSet=0" LINE_FEED @@ -380,29 +387,24 @@ write_waypoint(gbfile* fout, const waypoint* wpt, const int waypt_no, const char "Time=%.10f00000" LINE_FEED, 0.0, -32678.0, 65535.0, time ); - xfree(notes); } static void write_route_head_cb(const route_head* rte) { - char buff[32]; - char* name; + QString name; name = rte->rte_name; - if ((name == NULL) || (*name == '\0')) { - snprintf(buff, sizeof(buff), "Route%d", rte_index); - name = buff; + if (name.isEmpty()) { + name=QString("Route%1").arg(rte_index); } name = mkshort(hshort_rte, name); gbfprintf(fout, "[Rt%d]" LINE_FEED "Name=%s" LINE_FEED "Visible=1" LINE_FEED, rte_index, - name + CSTR(name) ); - xfree(name); - rte_index++; rte_wpt_index = 0; } diff --git a/gpsbabel/skyforce.cc b/gpsbabel/skyforce.cc index 50637c933..6c53b7cbb 100644 --- a/gpsbabel/skyforce.cc +++ b/gpsbabel/skyforce.cc @@ -174,8 +174,6 @@ skyforce_waypt_disp_cb(const waypoint* wpt) tm = *gmtime(&tt); strftime(buf + 2, sizeof(buf) - 2, "%d%m%y %H%M%S ", &tm); } else { - char* name; - if (rte_num > 999) { return; } @@ -187,6 +185,7 @@ skyforce_waypt_disp_cb(const waypoint* wpt) } return; } + QString name; if (global_opts.synthesize_shortnames) { name = mkshort_from_wpt(short_h, wpt); } else { @@ -196,9 +195,7 @@ skyforce_waypt_disp_cb(const waypoint* wpt) if (global_opts.objective == rtedata) { snprintf(buf + 2, sizeof(buf) - 2, "%03d ", rte_num); } - snprintf(buf + 6, sizeof(buf) - 6, "%03d %-9s ", wpt_num, name); - - xfree(name); + snprintf(buf + 6, sizeof(buf) - 6, "%03d %-9s ", wpt_num, CSTR(name)); } diff --git a/gpsbabel/skytraq.cc b/gpsbabel/skytraq.cc index 5a5f6f1c6..8d0206a36 100644 --- a/gpsbabel/skytraq.cc +++ b/gpsbabel/skytraq.cc @@ -267,7 +267,8 @@ skytraq_rd_msg(const void* payload, unsigned int len) { int errors = 5; /* allow this many errors */ unsigned int c, i, state; - unsigned int rcv_len, calc_cs, rcv_cs; + signed int rcv_len; + unsigned int calc_cs, rcv_cs; for (i = 0, state = 0; i < RETRIES && state < sizeof(MSG_START); i++) { c = rd_char(&errors); @@ -1596,7 +1597,7 @@ static const char* mhport; static void miniHomer_rd_init(const char* fname) { - opt_set_location=""; // otherwise it will lead to bus error + opt_set_location=NULL; // otherwise it will lead to bus error skytraq_rd_init(fname); // sets global var serial_handle mhport=fname; } diff --git a/gpsbabel/sort.cc b/gpsbabel/sort.cc index e670ddf21..1f523f539 100644 --- a/gpsbabel/sort.cc +++ b/gpsbabel/sort.cc @@ -66,9 +66,17 @@ sort_comp(const queue* a, const queue* b) case sm_gcid: return x1->gc_data->id - x2->gc_data->id; case sm_shortname: +#if NEW_STRINGS + return x1->shortname.compare(x2->shortname); +#else return strcmp(x1->shortname, x2->shortname); +#endif case sm_description: +#if NEW_STRINGS + return x1->description.compare(x2->description); +#else return strcmp(x1->description, x2->description); +#endif case sm_time: return x1->GetCreationTime().toTime_t() - x2->GetCreationTime().toTime_t(); default: diff --git a/gpsbabel/stmsdf.cc b/gpsbabel/stmsdf.cc index cff4241c2..eb05bbf2b 100644 --- a/gpsbabel/stmsdf.cc +++ b/gpsbabel/stmsdf.cc @@ -61,8 +61,8 @@ static int datum; static int filetype; static route_head* route; static queue trackpts; -static char* rte_name; -static char* rte_desc; +static QString rte_name; +static QString rte_desc; static waypoint* trkpt_out; static route_head* trk_out; @@ -212,7 +212,7 @@ finalize_tracks(void) trackno++; if (rte_name != NULL) { if (trackno > 1) { - xasprintf(&track->rte_name, "%s (%d)", rte_name, trackno); + xasprintf(&track->rte_name, "%s (%d)", CSTR(rte_name), trackno); } else { track->rte_name = xstrdup(rte_name); } @@ -366,7 +366,7 @@ rd_init(const char* fname) route = NULL; datum = DATUM_WGS84; filetype = 28; - rte_name = rte_desc = NULL; + rte_name = rte_desc = QString(); QUEUE_INIT(&trackpts); } @@ -375,12 +375,8 @@ static void rd_deinit(void) { gbfclose(fin); - if (rte_name) { - xfree(rte_name); - } - if (rte_desc) { - xfree(rte_desc); - } + rte_name = QString(); + rte_desc = QString(); } static void @@ -507,7 +503,11 @@ any_hdr_calc_cb(const route_head* trk) return; } - if (!rte_name && trk->rte_name) { +#if NEW_STRINGS + if (rte_name.isEmpty() && !trk->rte_name.isEmpty()) { +#else + if (rte_name.isEmpty() && trk->rte_name) { +#endif rte_name = trk->rte_name; rte_desc = trk->rte_desc; } @@ -603,17 +603,17 @@ track_disp_wpt_cb(const waypoint* wpt) } if (flag == 1) { - const char* name = wpt->shortname; + QString name = wpt->shortname; if (name == NULL) { name = "Log paused"; } - gbfprintf(fout, "\"MP\",\"%s\"", name); + gbfprintf(fout, "\"MP\",\"%s\"", CSTR(name)); } else if (flag == 2) { - const char* name = wpt->shortname; + QString name = wpt->shortname; if (name == NULL) { name = "Log continued"; } - gbfprintf(fout, "\"MP\",\"%s\"", name); + gbfprintf(fout, "\"MP\",\"%s\"", CSTR(name)); } else { gbfprintf(fout, "\"TP\""); } @@ -653,7 +653,7 @@ static void route_disp_wpt_cb(const waypoint* wpt) { if (this_route_valid) { - char* sn; + QString sn; if (global_opts.synthesize_shortnames) { sn = mkshort_from_wpt(short_h, wpt); @@ -661,8 +661,7 @@ route_disp_wpt_cb(const waypoint* wpt) sn = mkshort(short_h, wpt->shortname); } gbfprintf(fout, "\"WP\",\"%s\",%.8lf,%.8lf,%.f\n", - sn, wpt->latitude, wpt->longitude, ALT(wpt)); - xfree(sn); + CSTR(sn), wpt->latitude, wpt->longitude, ALT(wpt)); } } @@ -696,8 +695,8 @@ data_write(void) gbfprintf(fout, "SOURCE=FILE\n"); gbfprintf(fout, "DATUM=WGS84\n"); - rte_name = NULL; - rte_desc = NULL; + rte_name = QString(); + rte_desc = QString(); trkpt_out = NULL; opt_route_index_value = -1; /* take all tracks from data pool */ track_index = 0; @@ -729,8 +728,8 @@ data_write(void) opt_route_index_value = atoi(opt_route_index); route_disp_all(any_hdr_calc_cb, any_tlr_calc_cb, any_waypt_calc_cb); gbfprintf(fout, "DISTANCE=%.f\n", all_dist); - if (rte_name) { - gbfprintf(fout, "NAME=%s\n", rte_name); + if (!rte_name.isEmpty()) { + gbfprintf(fout, "NAME=%s\n", CSTR(rte_name)); } gbfprintf(fout, "[POINTS]\n"); if (route_points > 0) { @@ -744,8 +743,8 @@ data_write(void) track_disp_all(any_hdr_calc_cb, any_tlr_calc_cb, any_waypt_calc_cb); if (all_track_points > 0) { - if (rte_name) { - gbfprintf(fout, "NAME=%s\n", rte_name); + if (!rte_name.isEmpty()) { + gbfprintf(fout, "NAME=%s\n", CSTR(rte_name)); } if (minalt != -unknown_alt) { gbfprintf(fout, "MINALT=%.f\n", minalt); diff --git a/gpsbabel/stmwpp.cc b/gpsbabel/stmwpp.cc index 303a2cdbb..e551c7aac 100644 --- a/gpsbabel/stmwpp.cc +++ b/gpsbabel/stmwpp.cc @@ -135,7 +135,11 @@ stmwpp_data_read(void) break; case 2: +#if NEW_STRINGS + wpt->shortname = QString::fromLatin1(c); +#else wpt->shortname = xstrdup(c); +#endif break; case 3: @@ -246,8 +250,8 @@ stmwpp_waypt_cb(const waypoint* wpt) snprintf(cdate, sizeof(cdate), "%02d/%02d/%04d", tm.tm_mon, tm.tm_mday, tm.tm_year); snprintf(ctime, sizeof(ctime), "%02d:%02d:%02d", tm.tm_hour, tm.tm_min, tm.tm_sec); + QString sn; switch (what) { - char* sn; case STM_WAYPT: case STM_RTEPT: @@ -256,8 +260,7 @@ stmwpp_waypt_cb(const waypoint* wpt) } else { sn = mkshort(short_h, wpt->shortname); } - gbfprintf(fout, "WP,D,%s,", sn); - xfree(sn); + gbfprintf(fout, "WP,D,%s,", CSTR(sn)); break; case STM_TRKPT: diff --git a/gpsbabel/tef_xml.cc b/gpsbabel/tef_xml.cc index 3215f78f5..daab9674d 100644 --- a/gpsbabel/tef_xml.cc +++ b/gpsbabel/tef_xml.cc @@ -129,7 +129,7 @@ tef_list_start(xg_string args, const QXmlStreamAttributes* attrv) */ static char* -fix_notes(const char* name, char* notes) +fix_notes(char* name, char* notes) { const char* cleft, *cright, *cback; char* ctmp; @@ -162,6 +162,20 @@ fix_notes(const char* name, char* notes) return notes; } +static char* +fix_notes(const QString& name, const QString& notes) +{ + +// WTH? fix_notes() modifies the note string...and +// may reallocate it. + char* cname = xstrdup(name); + char* cnotes = xstrdup(notes); + char *r = fix_notes(cname, cnotes); + xfree(cname); + xfree(cnotes); + return r; +} + static void waypoint_final() { @@ -175,7 +189,11 @@ waypoint_final() if (version < 2) { /* keep the old behaviour */ wpt_tmp->notes = wpt_tmp->description; +#if NEW_STRINGS + wpt_tmp->description = QString(); +#else wpt_tmp->description = NULL; +#endif } wpt_tmp->notes = fix_notes(wpt_tmp->shortname, wpt_tmp->notes); diff --git a/gpsbabel/text.cc b/gpsbabel/text.cc index b5bd0d1eb..408824505 100644 --- a/gpsbabel/text.cc +++ b/gpsbabel/text.cc @@ -121,7 +121,7 @@ text_disp(const waypoint* wpt) } xasprintf(&tmpout2, "%s (%d%c %6.0f %7.0f)%s", tmpout1, utmz, utmzc, utme, utmn, altout); gbfprintf(file_out, "%-16s %59s\n", - (global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname, + (global_opts.synthesize_shortnames) ? CSTRc(mkshort_from_wpt(mkshort_handle, wpt)) : CSTRc(wpt->shortname), tmpout2); xfree(tmpout2); xfree(tmpout1); @@ -129,8 +129,11 @@ text_disp(const waypoint* wpt) xfree(altout); } - +#if NEW_STRINGS + if (wpt->description != wpt->shortname) { +#else if (strcmp(wpt->description, wpt->shortname)) { +#endif gbfprintf(file_out, "%s", CSTRc(wpt->description)); if (!wpt->gc_data->placer.isEmpty()) { gbfprintf(file_out, " by %s", wpt->gc_data->placer.toUtf8().data()); @@ -156,12 +159,16 @@ text_disp(const waypoint* wpt) if (txt_encrypt) { hint = rot13(wpt->gc_data->hint); } else { - hint = xstrdup(wpt->gc_data->hint.toUtf8().data()); + hint = xstrdup(wpt->gc_data->hint); } gbfprintf(file_out, "\nHint: %s\n", hint); xfree(hint); } +#if NEW_STRINGS + } else if (!wpt->notes.isEmpty() && (wpt->description.isEmpty() || wpt->notes != wpt->description)) { +#else } else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) { +#endif gbfprintf(file_out, "\n%s\n", CSTRc(wpt->notes)); } diff --git a/gpsbabel/tiger.cc b/gpsbabel/tiger.cc index b549241ec..1d67f3269 100644 --- a/gpsbabel/tiger.cc +++ b/gpsbabel/tiger.cc @@ -212,17 +212,16 @@ tiger_disp(const waypoint* wpt) gbfprintf(file_out, "%f,%f:%s", lon, lat, pin.toUtf8().data()); if (!nolabels) { - char* temp = NULL; - char* desc = csv_stringclean(wpt->description, ":"); + QString temp; + QString desc = csv_stringclean(wpt->description, ":"); if (global_opts.synthesize_shortnames) { temp = desc; desc = mkshort(mkshort_whandle, desc); } - gbfprintf(file_out, ":%s", desc); + gbfprintf(file_out, ":%s", CSTR(desc)); if (temp != NULL) { desc = temp; } - xfree(desc); } gbfprintf(file_out, "\n"); } diff --git a/gpsbabel/tmpro.cc b/gpsbabel/tmpro.cc index 9f8eb02aa..4130a67a3 100644 --- a/gpsbabel/tmpro.cc +++ b/gpsbabel/tmpro.cc @@ -178,11 +178,17 @@ tmpro_waypt_pr(const waypoint* wpt) { int icon = 1; /* default to "flag" */ int colour = 255; /*default to red */ +#if NEW_STRINGS + QString shortname; + QString description; + if ((wpt->shortname.isEmpty()) || (global_opts.synthesize_shortnames)) { + if (!wpt->description.isEmpty()) { +#else char* shortname = NULL; char* description = NULL; - if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) { if (wpt->description) { +#endif if (global_opts.synthesize_shortnames) { shortname = mkshort_from_wpt(mkshort_handle, wpt); } else { @@ -196,8 +202,13 @@ tmpro_waypt_pr(const waypoint* wpt) shortname = csv_stringclean(wpt->shortname, ",\""); } +#if NEW_STRINGS + if (wpt->description.isEmpty()) { + if (!shortname.isEmpty()) { +#else if (! wpt->description) { if (shortname) { +#endif description = csv_stringclean(shortname, ",\""); } else { description = xstrdup(""); @@ -218,8 +229,8 @@ tmpro_waypt_pr(const waypoint* wpt) l = xstrdup(link.url_.toUtf8().data()); } gbfprintf(file_out, "new\t%.6s\t%.80s\t%08.6f\t%08.6f\t\t\t%.2f\t%d\t%d\t%.128s\n", - shortname, - description, + CSTRc(shortname), + CSTRc(description), wpt->latitude, wpt->longitude, wpt->altitude, @@ -228,13 +239,15 @@ tmpro_waypt_pr(const waypoint* wpt) l ? l : "" ); - +#if NEW_STRINGS +#else if (description) { xfree(description); } if (shortname) { xfree(shortname); } +#endif if (l) { xfree(l); } diff --git a/gpsbabel/tomtom.cc b/gpsbabel/tomtom.cc index fe39f155a..9c33022bd 100644 --- a/gpsbabel/tomtom.cc +++ b/gpsbabel/tomtom.cc @@ -259,7 +259,11 @@ compare_lat(const void* a, const void* b) return 1; } if (wa->wpt->longitude - wb->wpt->longitude == 0) { +#if NEW_STRINGS + return wa->wpt->shortname.compare(wb->wpt->shortname); +#else return strcmp(wa->wpt->shortname, wb->wpt->shortname); +#endif } return compare_lon(a,b); } @@ -279,7 +283,11 @@ compare_lon(const void* a, const void* b) return 1; } if (wa->wpt->latitude - wb->wpt->latitude == 0) { +#if NEW_STRINGS + return wa->wpt->shortname.compare(wb->wpt->shortname); +#else return strcmp(wa->wpt->shortname, wb->wpt->shortname); +#endif } return compare_lat(a,b); } @@ -371,7 +379,11 @@ compute_blocks(struct hdr* start, int count, newblock->size += 4 * 3 + 1; /* wpt const part 3 longs, 1 char */ wpt = start[i].wpt; +#if NEW_STRINGS + newblock->size += wpt->description.length() + 1; +#else newblock->size += strlen(wpt->description) + 1; +#endif } } else { if ((maxlat-minlat)>(maxlon-minlon)) { diff --git a/gpsbabel/tpg.cc b/gpsbabel/tpg.cc index ac33e0ce6..576e2fab5 100644 --- a/gpsbabel/tpg.cc +++ b/gpsbabel/tpg.cc @@ -173,8 +173,8 @@ tpg_waypt_pr(const waypoint* wpt) short int elev; char tbuf[64]; char c,ocount; - char* shortname; - char* description; + QString shortname; + QString description; int i; /* these unknown 4 are probably point properties (color, icon, etc..) */ @@ -190,8 +190,13 @@ tpg_waypt_pr(const waypoint* wpt) * and a shortname */ +#if NEW_STRINGS + if ((wpt->shortname.isEmpty()) || (global_opts.synthesize_shortnames)) { + if (!wpt->description.isEmpty()) { +#else if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) { if (wpt->description) { +#endif if (global_opts.synthesize_shortnames) { shortname = mkshort_from_wpt(mkshort_handle, wpt); } else { @@ -204,9 +209,12 @@ tpg_waypt_pr(const waypoint* wpt) } else { shortname = xstrdup(wpt->shortname); } - +#if NEW_STRINGS + if (wpt->description.isEmpty()) { +#else if (! wpt->description) { - if (shortname) { +#endif + if (!shortname.isEmpty()) { description = xstrdup(shortname); } else { description = xstrdup(""); @@ -233,7 +241,7 @@ tpg_waypt_pr(const waypoint* wpt) elev = (short int) METERS_TO_FEET(wpt->altitude); /* 1 bytes stringsize for shortname */ - c = strlen(shortname); + c = shortname.length(); ocount = 0; /* * It's reported the only legal characters are upper case @@ -241,7 +249,7 @@ tpg_waypt_pr(const waypoint* wpt) * count and one to output. */ for (i = 0; i < c; i++) { - char oc = toupper(shortname[i]); + char oc = shortname[i].toUpper().cell(); if (isalnum(oc) || oc == ' ') { ocount++; } @@ -250,7 +258,7 @@ tpg_waypt_pr(const waypoint* wpt) gbfwrite(&ocount, 1, 1, tpg_file_out); for (i = 0; i < c; i++) { - char oc = toupper(shortname[i]); + char oc = shortname[i].toUpper().cell(); if (isalnum(oc) || oc == ' ') { gbfputc(oc, tpg_file_out); } @@ -280,9 +288,6 @@ tpg_waypt_pr(const waypoint* wpt) } else { gbfwrite(unknown2, 1, 2, tpg_file_out); } - - xfree(shortname); - xfree(description); } static void diff --git a/gpsbabel/trackfilter.cc b/gpsbabel/trackfilter.cc index b89ba45d7..10f8f567b 100644 --- a/gpsbabel/trackfilter.cc +++ b/gpsbabel/trackfilter.cc @@ -334,7 +334,7 @@ trackfilter_fill_track_list_cb(const route_head* track) /* callback for track_d if (opt_name != NULL) { if ((track->rte_name == NULL) || - (case_ignore_str_match(track->rte_name, opt_name) == 0)) { + (case_ignore_str_match(CSTRc(track->rte_name), opt_name) == 0)) { QUEUE_FOR_EACH((queue*)&track->waypoint_list, elem, tmp) { waypoint* wpt = (waypoint*)elem; track_del_wpt((route_head*)track, wpt); @@ -404,16 +404,23 @@ trackfilter_split_init_rte_name(route_head* track, const QDateTime dt) } else { snprintf(buff, sizeof(buff), "%s-%s", opt_title, tbuff); } +#if NEW_STRINGS + } else if (!track->rte_name.isEmpty()) { +#else } else if ((track->rte_name != NULL) && (strlen(track->rte_name) > 0)) { +#endif snprintf(buff, sizeof(buff), "%s-%s", CSTRc(track->rte_name), tbuff); } else { strncpy(buff, tbuff, sizeof(buff)); } - +#if NEW_STRINGS + track->rte_name = buff; +#else if (track->rte_name != NULL) { xfree(track->rte_name); } track->rte_name = xstrdup(buff); +#endif } static void @@ -436,11 +443,14 @@ trackfilter_pack_init_rte_name(route_head* track, const time_t default_time) } else { strncpy(buff, opt_title, sizeof(buff)); } - +#if NEW_STRINGS + track->rte_name = buff; +#else if (track->rte_name != NULL) { xfree(track->rte_name); } track->rte_name = xstrdup(buff); +#endif } /******************************************************************************* @@ -969,7 +979,11 @@ trackfilter_seg2trk(void) dest = route_head_alloc(); dest->rte_num = src->rte_num; /* name in the form TRACKNAME #n */ +#if NEW_STRINGS + if (!src->rte_name.isEmpty()) { +#else if (src->rte_name) { +#endif xasprintf(&dest->rte_name, "%s #%d", CSTRc(src->rte_name), ++trk_seg_num); } diff --git a/gpsbabel/transform.cc b/gpsbabel/transform.cc index 53c4c6327..190f2eb1f 100644 --- a/gpsbabel/transform.cc +++ b/gpsbabel/transform.cc @@ -34,8 +34,11 @@ static route_head* current_trk; static route_head* current_rte; static char* opt_routes, *opt_tracks, *opt_waypts, *opt_delete, *rpt_name_digits, *opt_rpt_name; - +#if NEW_STRINGS +static QString current_namepart; +#else static char* current_namepart; +#endif static int name_digits, use_src_name; @@ -108,13 +111,21 @@ static void transform_rte_disp_hdr_cb(const route_head* rte) { current_namepart = RPT; +#if NEW_STRINGS + if (!rte->rte_name.isEmpty() && use_src_name) { +#else if (rte->rte_name && *rte->rte_name && use_src_name) { +#endif current_namepart = rte->rte_name; } if (current_target == 'T') { current_trk = route_head_alloc(); track_add_head(current_trk); +#if NEW_STRINGS + if (!rte->rte_name.isEmpty()) { +#else if (rte->rte_name && *rte->rte_name) { +#endif xasprintf(¤t_trk->rte_desc, "Generated from route %s", CSTRc(rte->rte_name)); current_trk->rte_name = xstrdup(rte->rte_name); /* name the new trk */ } @@ -125,16 +136,28 @@ static void transform_trk_disp_hdr_cb(const route_head* trk) { current_namepart = RPT; +#if NEW_STRINGS + if (!trk->rte_name.isEmpty() && use_src_name) { +#else if (trk->rte_name && *trk->rte_name && use_src_name) { +#endif current_namepart = trk->rte_name; } if (current_target == 'R') { current_rte = route_head_alloc(); route_add_head(current_rte); +#if NEW_STRINGS + if (!trk->rte_name.isEmpty()) { + current_rte->rte_desc = "Generated from track "; + current_rte->rte_desc += trk->rte_name; + current_rte->rte_name = trk->rte_name; /* name the new rte */ + } +#else if (trk->rte_name && *trk->rte_name) { xasprintf(¤t_rte->rte_desc, "Generated from track %s", CSTRc(trk->rte_name)); current_rte->rte_name = xstrdup(trk->rte_name); /* name the new rte */ } +#endif } } diff --git a/gpsbabel/unicsv.cc b/gpsbabel/unicsv.cc index 9b14ca8e3..f2b5e1d5f 100644 --- a/gpsbabel/unicsv.cc +++ b/gpsbabel/unicsv.cc @@ -1242,7 +1242,11 @@ unicsv_fatal_outside(const waypoint* wpt) { gbfprintf(fout, "#####\n"); fatal(MYNAME ": %s (%s) is outside of convertable area of grid \"%s\"!\n", +#if NEW_STRINGS + wpt->shortname.isEmpty() ? "Waypoint" : CSTR(wpt->shortname), +#else wpt->shortname ? CSTRc(wpt->shortname) : "Waypoint", +#endif pretty_deg_format(wpt->latitude, wpt->longitude, 'd', NULL, 0), gt_get_mps_grid_longname(unicsv_grid_idx, MYNAME)); } @@ -1264,14 +1268,6 @@ unicsv_print_str(const QString& s) gbfputs(t.trimmed(), fout); } -#if NEW_STRINGS -static void -unicsv_print_str(const String& s) -{ - unicsv_print_str(s.s_); -} -#endif - static void unicsv_print_data_time(const QDateTime& idt) { @@ -1307,11 +1303,20 @@ unicsv_waypt_enum_cb(const waypoint* wpt) if (!wpt->icon_descr.isNull()) { gb_setbit(&unicsv_outp_flags, fld_symbol); } +#if NEW_STRINGS + if (!wpt->description.isEmpty() && shortname != wpt->description) { +#else if (wpt->description && *wpt->description && shortname != wpt->description) { +#endif gb_setbit(&unicsv_outp_flags, fld_description); } +#if NEW_STRINGS + if (!wpt->notes.isEmpty() && shortname != wpt->notes) { + if ((wpt->description.isEmpty()) || (wpt->description != wpt->notes)) { +#else if (wpt->notes && *wpt->notes && shortname != wpt->notes) { if ((! wpt->description) || (strcmp(wpt->description, wpt->notes) != 0)) { +#endif gb_setbit(&unicsv_outp_flags, fld_notes); } } @@ -1447,12 +1452,11 @@ unicsv_waypt_disp_cb(const waypoint* wpt) { double lat, lon, alt; char* cout = NULL; - const char* shortname; garmin_fs_t* gmsd; const geocache_data* gc_data = NULL; unicsv_waypt_ct++; - shortname = (wpt->shortname) ? CSTRc(wpt->shortname) : ""; + QString shortname = wpt->shortname; gmsd = GMSD_FIND(wpt); if (unicsv_datum_idx == DATUM_WGS84) { diff --git a/gpsbabel/vitosmt.cc b/gpsbabel/vitosmt.cc index cdc788ae7..57e7da361 100644 --- a/gpsbabel/vitosmt.cc +++ b/gpsbabel/vitosmt.cc @@ -170,8 +170,12 @@ vitosmt_read(void) double usec = fmod(1000000*seconds+0.5,1000000); wpt_tmp->SetCreationTime(mkgmtime(&tmStruct), lround(usec/1000.0)); +#if NEW_STRINGS + wpt_tmp->shortname = QString().sprintf("WP%04d", ++serial); +#else wpt_tmp->shortname = (char*) xcalloc(16,1); snprintf(wpt_tmp->shortname, 15 , "WP%04d", ++serial); +#endif WAYPT_SET(wpt_tmp, speed, KNOTS_TO_MPS(speed)); /* meters per second */ WAYPT_SET(wpt_tmp, course, course); diff --git a/gpsbabel/waypt.cc b/gpsbabel/waypt.cc index 027d3f4a6..285eb5a11 100644 --- a/gpsbabel/waypt.cc +++ b/gpsbabel/waypt.cc @@ -69,7 +69,8 @@ waypt_dupe(const waypoint* wpt) */ waypoint* tmp = new waypoint; *tmp = *wpt; - +#if NEW_STRINGS +#else if (wpt->shortname) { tmp->shortname = xstrdup(wpt->shortname); } @@ -79,6 +80,7 @@ waypt_dupe(const waypoint* wpt) if (wpt->notes) { tmp->notes = xstrdup(wpt->notes); } +#endif tmp->icon_descr = wpt->icon_descr; @@ -172,6 +174,21 @@ waypt_add(waypoint* wpt) * try to be sure that we have these fields even if just by * copying them from elsewhere. */ +#if NEW_STRINGS + // Note tests for isNull here as some formats intentionally set "". + // This is kind of goofy, but it emulates the C string implementation. + if (wpt->shortname.isNull()) { + if (!wpt->description.isNull()) { + wpt->shortname = wpt->description; + } else if (!wpt->notes.isNull()) { + wpt->shortname = wpt->notes; + } else { + QString n; + n.sprintf("%03d", waypt_ct); + wpt->shortname = QString("WPT%1").arg(n); + } + } +#else if (wpt->shortname == NULL) { if (wpt->description) { wpt->shortname = xstrdup(wpt->description); @@ -184,7 +201,19 @@ waypt_add(waypoint* wpt) wpt->shortname = sn; } } +#endif +#if NEW_STRINGS + if (wpt->description.isEmpty()) { + if (!wpt->notes.isNull()) { + wpt->description = wpt->notes; + } else { + if (!wpt->shortname.isNull()) { + wpt->description = wpt->shortname; + } + } + } +#else if (wpt->description == NULL || strlen(wpt->description) == 0) { if (wpt->description) { xfree(wpt->description); @@ -197,6 +226,7 @@ waypt_add(waypoint* wpt) } } } +#endif update_common_traits(wpt); @@ -257,13 +287,16 @@ waypt_disp(const waypoint* wpt) } printposn(wpt->latitude,1); printposn(wpt->longitude,0); - +#if NEW_STRINGS + if (!wpt->description.isEmpty()) { +#else if (wpt->description) { +#endif char* tmpdesc = xstrdup(wpt->description); printf("%s/%s", global_opts.synthesize_shortnames ? mkshort(mkshort_handle, tmpdesc) : - wpt->shortname, + CSTRc(wpt->shortname), tmpdesc); if (tmpdesc) { xfree(tmpdesc); @@ -409,6 +442,8 @@ waypt_free(waypoint* wpt) /* * This and waypt_dupe should be closely synced. */ +#if NEW_STRINGS +#else if (wpt->shortname) { xfree(wpt->shortname); } @@ -418,6 +453,7 @@ waypt_free(waypoint* wpt) if (wpt->notes) { xfree(wpt->notes); } +#endif if (wpt->gc_data != &empty_gc_data) { geocache_data* gc_data = (geocache_data*)wpt->gc_data; diff --git a/gpsbabel/wfff_xml.cc b/gpsbabel/wfff_xml.cc index 8afe9e349..d38264ac2 100644 --- a/gpsbabel/wfff_xml.cc +++ b/gpsbabel/wfff_xml.cc @@ -113,6 +113,21 @@ void wfff_s(xg_string args, const QXmlStreamAttributes* unused) ap_lat=0.0; ap_lon=0.0; } +#if NEW_STRINGS +// anything here involving 'xstrdup' should be fixed by fixing the underlying data type. +void wfff_mac(const QString& args, const QXmlStreamAttributes* unused) { ap_mac = xstrdup(args); } +void wfff_ssid(const QString& args, const QXmlStreamAttributes* unused) { ap_ssid = xstrdup(args); } +void wfff_type(const QString& args, const QXmlStreamAttributes* unused) { ap_type = xstrdup(args); } +void wfff_mnrssi(const QString& args, const QXmlStreamAttributes* unused) { ap_mnrssi = args.toDouble(); } +void wfff_mxrssi(const QString& args, const QXmlStreamAttributes* unused) { ap_mxrssi = args.toDouble(); } +void wfff_chan(const QString& args, const QXmlStreamAttributes* unused) { ap_chan = args.toInt(); } +void wfff_first(const QString& args, const QXmlStreamAttributes* unused) { ap_first = xml_parse_time(args).toTime_t(); } +void wfff_last(const QString& args, const QXmlStreamAttributes* unused) { ap_last = xstrdup(args); } +void wfff_wep(const QString& args, const QXmlStreamAttributes* unused) { ap_wep = xstrdup(args); } +void wfff_hdop(const QString& args, const QXmlStreamAttributes* unused) { ap_hdop = args.toDouble(); } +void wfff_lat(const QString& args, const QXmlStreamAttributes* unused) { ap_lat = args.toDouble(); } +void wfff_lon(const QString& args, const QXmlStreamAttributes* unused) { ap_lon = args.toDouble(); } +#else void wfff_mac(xg_string args, const QXmlStreamAttributes* unused) { @@ -197,6 +212,7 @@ void wfff_lon(xg_string args, const QXmlStreamAttributes* unused) ap_lon = atof(args); } } +#endif /* End of AP Block, set waypoint and add */ static long tosscount=0; diff --git a/gpsbabel/xcsv.cc b/gpsbabel/xcsv.cc index 456836ccf..76b33e5cf 100644 --- a/gpsbabel/xcsv.cc +++ b/gpsbabel/xcsv.cc @@ -704,10 +704,14 @@ xcsv_wr_position(waypoint* wpt) /* Tweak incoming name if we don't have a fix */ switch (wpt->fix) { case fix_none: +#if NEW_STRINGS + wpt->shortname = "ESTIMATED Position"; +#else if (wpt->shortname) { xfree(wpt->shortname); } wpt->shortname = xstrdup("ESTIMATED Position"); +#endif break; default: break; diff --git a/gpsbabel/yahoo.cc b/gpsbabel/yahoo.cc index 5aa566b4d..dfd2e8ee1 100644 --- a/gpsbabel/yahoo.cc +++ b/gpsbabel/yahoo.cc @@ -92,20 +92,35 @@ void wpt_e(xg_string args, const QXmlStreamAttributes* unused) void wpt_lat(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->latitude = args.toDouble(); +#else wpt_tmp->latitude = atof(args); +#endif } void wpt_lon(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + wpt_tmp->longitude = args.toDouble(); +#else wpt_tmp->longitude = atof(args); +#endif } void wpt_addr(xg_string args, const QXmlStreamAttributes* unused) { +#if NEW_STRINGS + if (!wpt_tmp->notes.isEmpty()) { + wpt_tmp->notes += as; + } + wpt_tmp->notes += args; +#else if (wpt_tmp->notes) { wpt_tmp->notes = xstrappend(wpt_tmp->notes, as); } wpt_tmp->notes = xstrappend(wpt_tmp->notes, args); +#endif } ff_vecs_t yahoo_vecs = { -- 2.30.2